执行命令sudo useradd --help
报错如下:
fuyun is not in the sudoers file. This incident will be reported.
原因:该用户暂没有root权限
解决办法:修改sudoers文件
切换到root用户下,su -,
运行visudo
命令,visudo命令是用来编辑修改/etc/sudoers配置文件
visudo
如下图所示,在如下位置添加用户名、ALL=(ALL)、NOPASSWD:ALL
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
fuyun ALL=(ALL) NOPASSWD:ALL
说明:如果没有添加NOPASSWD: 则每次sudo都需要root账户的密码
测试:
执行命令exit
退出root账户
再次执行文章第一条命令
[fuyun@bigdata-training hive-3.1.1]$ sudo useradd -help
useradd: invalid option -- 'h'
Usage: useradd [options] LOGIN
Options:
-b, --base-dir BASE_DIR base directory for the home directory of the
new account #新账户的主目录的基目录
-c, --comment COMMENT GECOS field of the new account #新账户的GECOS字段
-d, --home-dir HOME_DIR home directory of the new account #新账户的家目录
-D, --defaults print or change default useradd configuration #显示或变更
-e, --expiredate EXPIRE_DATE expiration date of the new account #新账户的过期日期
-f, --inactive INACTIVE password inactivity period of the new account #新账户的密码不活动期
-g, --gid GROUP name or ID of the primary group of the new
account #新账户的主组或ID
-G, --groups GROUPS list of supplementary groups of the new
account #新账户的附加主列表
-h, --help display this help message and exit #显示此帮助信息并退出
-k, --skel SKEL_DIR use this alternative skeleton directory #使用此目录作为骨架目录
-K, --key KEY=VALUE override /etc/login.defs defaults #不使用/etc/login.defs的默认值
-l, --no-log-init do not add the user to the lastlog and
faillog databases #不要将此目录添加到最近登录或登录失败的数据库
-m, --create-home create the user's home directory #创建用户的主目录
-M, --no-create-home do not create the user's home directory #不创建用户的主目录
-N, --no-user-group do not create a group with the same name as
the user #不创建同名的组
-o, --non-unique allow to create users with duplicate
(non-unique) UID #允许使用重复的UID创建用户
-p, --password PASSWORD encrypted password of the new account #加密后的新账户密码
-r, --system create a system account #创建一个系统用户
-s, --shell SHELL login shell of the new account #新账户的登录shell
-u, --uid UID user ID of the new account #新账户的用户ID
-U, --user-group create a group with the same name as the user #创建与用户同名的组
-Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping #为SELinux用户映射使用指定的SEUSER
不再报错