如何禁止root用户直接登录Linux服务器

如何禁止root用户直接登录Linux服务器

用root用户登录有太多的弊端,因为权限太大,可能一不小心删错了文件,带来严重的后果。禁止root用户登录,从某种意义上说,也有利于服务器安全。

出于安全方面的考虑,先增加一个普通权限的用户,再使用su命令切换到root用户。

1. 创建普通权限的用户,用户名为 fuwuqi110.com

# useradd fuwuqi110.com

2. 为fuwuqi110.com用户设置密码

# passwd fuwuqi110.com
Changing password for user fuwuqi110.com.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

3. 修改sshd_config文件如下

# vi /etc/ssh/sshd_config
#PermitRootLogin yes 
 修改如下
PermitRootLogin no

4. 重启ssh服务

# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]

登陆方法为用上面创建的普通用户登录。如果想使用root用户,使用su命令切换到root用户。

服务器出问题没人兜底?交给我们值守

7×24 监控告警 + 分钟级响应,含安全加固、备份、迁移与故障处理。先做一次免费体检再决定。