rhel7 配置普通用户使用sudo
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
完毕。