平时用惯了root
登录,一时间添加新用户倒不太适应。没有什么难度,纯粹记录一下方便查找。
添加新用户
# useradd -m test
# passwd test
-m
用来在创建用户的同时为其创建home
目录。详细参数可见useradd --help
。如果需要为用户添加超级用户权限,由将其添加到sudoers
中,如果不需要,则忽略下一步。
将用户添加到 sudoers 中[可选]
有两种方法,二者取其一即可。
-
修改
/etc/sudoers
文件。# vim /etc/sudoers
可以在 vim 中搜索
root
。复制root ALL=(ALL) ALL
,粘贴到另一行,并将root
改为新的用户名即可,如test ALL=(ALL) ALL
。 -
将新用户添加到超级用户组中,组名一般是
wheel
,可以在/etc/sudoers
文件中查到该组,通常设置如%wheel ALL=(ALL) ALL
。注意:不需要修改/etc/sudoers
文件,只是去了解一下而已,有兴趣可以看一下该文件的注释。以下命令将用户test
添加到wheel
组中。# usermod -a test -G wheel
将用户添加到 sshd_config 中
# vim /etc/ssh/sshd_config
将AllowUsers username1 username2
或者AllowGroups groupname1 groupname2
添加到该文件。如果还要允许root
登录,则将PermitRootLogin yes
的注释去掉(另外还要将root
添加到允许登录的用户或用户组中)。
重启 sshd
# systemctl restart sshd