尝试执行如下命令

1
pkexec visudo

如果报错

1
2
3
4
5
6
7
8
9
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/sbin/visudo' as the super user
Authenticating as: ubuntu,,, (ubuntu)
Password:
polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie
==== AUTHENTICATION FAILED ===
Error executing command as another user: Not authorized
This incident has been reported.
————————————————

打开两个终端(终端1、终端2)
终端1

1
echo $$

终端2

1
pkttyagent --process 终端1的结果

终端1

1
pkexec visudo