Linux系统 sudo su命令报 ...is not in the sudoers file. This incident will be reported.

当普通用户无法使用sudo命令时,可能是因为不在sudoers文件中。解决方法包括:1) 切换到root用户,修改sudoers文件添加用户权限;2) 使用usermod命令将用户加入具有sudo权限的用户组;3) 利用sudoers文件的别名或包含机制进行设置。遵循步骤后,用户将能够成功执行sudo命令。

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

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的联合使用

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值