禁用root
账号登录
创建新的用户
创建一个test
用户useradd test
设置密码passwd test
设置test
用户密码
此时test
用户已经可以通过ssh
登录禁用
root
用户登录
修改vi /etc/ssh/sshd_config
中的PermitRootLogin yes
为PermitRootLogin no
(如果没有请添加)重启
sshd
systemctl restart sshd
或systemctl restart sshd.service
, 此时root
账号已经无法登录
配置test
用户成sudo
用户(如果不需要sudo
用户无需配置)
- 使用
root
配置sudo
用户
如果当前不是root
登录, 请使用su root
登录root
账号 - 增加
sudo
用户
使用vi /etc/sudoers
打开文件
在root ALL=(ALL) ALL
下增加test ALL=(ALL) ALL
保存即可
如果文件编辑没有权限使用chmod u+w /etc/sudoers
增加写入权限修改后使用chmod u-w /etc/sudoers
去掉权限