Linux普通用户执行sudo权限设置

执行命令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

不再报错

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值