企业项目管理、ORK、研发管理与敏捷开发工具平台

网站首页 > 精选文章 正文

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

wudianyun 2025-03-29 23:07:32 精选文章 50 ℃

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

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

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

 # useradd awspack 

2. 为awspack用户设置密码

 # passwd awspack Changing password for user awspack. 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用户。

Tags:

最近发表
标签列表