添加用户test
useradd test -d /home/test -m -s /bin/bash -G sudo,users -c 备注内容
设置密码
passwd test
以上命令同时创建默认组和用户主目录,加入sudo和users组。
因为/etc/sudoers文件中将sudo组设置为可以sudo所有操作,所以如果要有sudo权限可以把用户加入sudo组。
以下是/etc/sudoers文件内容
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
查看用户所在组
groups test
删除用户及其主目录和默认组
useradd test -r
参考