问题描述:
为了给新建的账户添加sudo权限,所以需要在/etc/sudoers
文件中添加用户名,而/etc/sudoers
文件的权限为-r--r-----
,所以使用sudo chmod 777 /etc/sudoers
命令修改了该文见的权限,在修改权限并添加用户名后,发现使用sudo
命令会报错,大致报错内容如图:
这种情况下有两种解决方案:
方案一
知道root
密码,通过su root
切换为root
用户,执行chmod 440 /etc/sudoers
修改/etc/sudoers
文件的权限。
方案二
不知道root
密码,没有图形界面。
通过ssh
远程连接到服务器的普通用户,首先打开两个终端A
和B
,在终端A
中执行echo $$
命令,获取终端A
的PID,在终端B
中执行pkttyagent --process XXX
,其中XXX
为终端A
的PID。然后在终端A
中执行pkexec chmod 440 /etc/sudoers
,在终端B
中继续操作,就可以解决问题。
补充:
pkexec
命令的官方描述:
pkexec allows an authorized user to execute PROGRAM as another user. If username is not specified, then the program will be executed as the administrative super user, root.
希望可以帮助到大家,谢谢。