rhel7 配置普通用户使用sudo

本文提供了解决rhel服务器版本安装后默认创建的用户无法使用sudo的问题的方法,包括编辑sudoers文件、修改用户权限、验证用户组归属及测试使用sudo的流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

rhel服务器版本安装之后,默认创建的用户不能使用sudo。使用sudo,会提示 user1 is not in the sudoers file. This incident will be reported.

解决方法(比如创建的用户叫做user1, 密码user1pass):

1、直接运行visudo命令,或者vim /etc/sudoers 。 打开并编辑/etc/sudoers文件:

visudo
或者
vim /etc/sudoers

 

2、找到下边代码的位置,并删除第二行的 ‘#’

## Allows people in group wheel to run all commands
# %wheel        ALL=(ALL)       ALL

3、用root身份运行:

usermod -aG wheel user1

4、切换到user1用户,并查看是否已经属于wheel组:

su - user1
groups

如果显示为:

user1 wheel

即表示成功。

5、测试:

sudo whoami

显示类似下边代码即表明可以正常使用sudo:

$ sudo whoami
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for USERNAME:
root

 

完毕。

 

转载于:https://www.cnblogs.com/asmer-stone/p/5268750.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值