新装的虚拟机用户没有sudo权限会弹出以下警告,无法用root权限去更新yum
执行sudo yum -y update的时候
[sandwich@192 ~]$ sudo yum -y update
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 sandwich:
sandwich is not in the sudoers file. This incident will be reported.
这时候需要给sandwich这个用户分配sudo权限,请follow以下步骤吧
1.切换回root用户
[sandwich@192 ~]$ su root
Password:
2.添加sudo文件的写权限
[root@192 sandwich]# chmod u+w /etc/sudoers
3.给sudoers文件添加新用户
vi /etc/sudoers
找到这行 root ALL=(ALL) ALL,在他下面添加xxx ALL=(ALL) ALL (这里的xxx是你的用户名)
ps:这里说下你可以sudoers添加下面四行中任意一条
#允许用户yuser执行sudo命令(需要输入密码).
user ALL=(ALL) ALL
#允许用户组user里面的用户执行sudo命令(需要输入密码).
%user ALL=(ALL) ALL
#允许用户user执行sudo命令,并且在执行的时候不输入密码.
user ALL=(ALL) NOPASSWD: ALL
#允许用户组youuser里面的用户执行sudo命令,并且在执行的时候不输入密码.
%user ALL=(ALL) NOPASSWD: ALL
4.取消sudoers文件的写权限
[root@192 sandwich]# chmod u-w /etc/sudoers
这样新用户就可以使用sudo了。