如何禁止root账号远程登录

一、添加和root权限一样的用户

1、

adduser admin

passwd admin (修改密码)

 

2、修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,

root ALL=(ALL) ALL

admin ALL=(ALL) ALL

使用:wq!就可以保存了。 或者使用visudo命令来进入sudoers文件的编辑,就可以正常保存

 

二、禁止root远程登录

需要编辑/etc/ssh/sshd_config。

vim /etc/ssh/sshd_config 

PermitRootLogin yes    允许root密钥登录

PasswordAuthentication no    不能账号密码登录

 

重启 service sshd restart

 

怎么登录root?

先用别的用户登陆,在 su root 切回root用户

切换到root用户还要在输如密码

 

posted @ 2022-06-16 15:06  Yau0315  阅读(1123)  评论(0)    收藏  举报