Linux创建管理员用户,并禁用root用户登录
添加用户:
useradd username
设置密码:
passwd username
将用户添加到管理组:
# CentOS
usermod -aG wheel username
# Debian/Ubuntu
usermod -aG sudo username
禁用root用户
编辑sshd_config:
vi /etc/ssh/sshd_config
将PermitRootLogin的值设置为no:
PermitRootLogin no
重启sshd服务:
systemctl restart sshd
以上可禁止使用root用户ssh登录,但仍然可以使用普通用户切换到root。
如果要禁止root用户的shell权限,修改passwd文件:
vi /etc/passwd
找到root所在行,如下所示:
root:x:0:0:root:/root:/bin/bash
修改为:
root:x:0:0:root:/root:/sbin/nologin

