sudo 命令不再解释,普通用户登录使用sudo su 命令执行不成功,提示...is not in the sudoers file. This incident will be reported.
这是因为当前用户不具有sudo特权,其由sudoers配置文件来指定, 配置文件位于"/etc/sudoers". 先用su命令切换到root用户, 输入root密码
[zpp@192 ~]$ su -
Password:
[root@192 ~]#
这里还需要给sudoers文件添加写权限
[root@192 ~]# chmod u+w ../etc/sudoers
然后编辑sudoers文件
[root@192 ~]# vi ../etc/sudoers
找到如图所示
在 root ALL=(ALL) ALL 这一行下加一句
*** ALL=(ALL) ALL (***为你需要添加权限的用户名)
最后 wq!并且撤销sudoers的写权限
[root@192 ~]# chmod u-w ../etc/sudoers
Ctrl +d 退出当前用户 使用sudo su 输入当前用户密码 发现欧克了。
*****************************************************************************************************
另外还再网上找到其他几种解决办法可供参考
1,根据用户组及无密码的配置:
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
跟第一种配置方式相比,也就在前面多了一个“%”,用来表示用户组。最前面的“#”表示注释, 把"#"去掉即可生效; 而后面的"NOPASSWD:"即表示不需要输入密码就可以执行命令
设置了某个用户组具有sudo权限之后,使用usermod命令把相应的用户添加到该用户组就可以了:
usermod -a -G wheel linuxidcuser
2,通过别名问题来设置,有命令别名,账户别名,主机别名等,具体参考sudoers文件提供的例子:
## Host Aliases ## Groups of machines. You may prefer to use hostnames (perhaps using ## wildcards for entire domains) or IP addresses instead. # Host_Alias FILESERVERS = fs1, fs2 # Host_Alias MAILSERVERS = smtp, smtp2 ## User Aliases ## These aren't often necessary, as you can use regular groups ## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname ## rather than USERALIAS # User_Alias ADMINS = jsmith, mikem ## Command Aliases ## These are groups of related commands... ## Networking # Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig, /sbin/mii-tool
3,在sudoers文件的最后面有如下几行,利用include引入/etc/sudoers.d目录下的配置文件,
## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment) #includedir /etc/sudoers.d
sudo与su的联合使用