Following the instruction here I get:

pkexec visudo

==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/sbin/visudo' as the super user
Authenticating as: Thomas,,, (tuc) Password:  polkit-agent-helper-1:
error response to PolicyKit daemon:
GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for
Error executing command as another user: Not authorized

This incident has been reported.

I am doing this via ssh since the box I am doing this on is used as a music server with no screen and is rather inaccessible. This happened when I upgraded from Ubuntu 14.04 to 16.04. I tried to copy a sudoers file from another recent 16.04 installation, but I can't do that because of the sudoers file:

sudo mv ~/gyrf sudoers

>> /etc/sudoers: syntax error near line 36 <<<
>> /etc/sudoers: syntax error near line 37 <<<
>> /etc/sudoers: syntax error near line 38 <<<
>> /etc/sudoers: syntax error near line 39 <<<
>> /etc/sudoers: syntax error near line 40 <<<
>> /etc/sudoers: syntax error near line 41 <<<
>> /etc/sudoers: syntax error near line 42 <<<
>> /etc/sudoers: syntax error near line 43 <<<
>> /etc/sudoers: syntax error near line 44 <<<
>> /etc/sudoers: syntax error near line 45 <<<
>> /etc/sudoers: syntax error near line 46 <<<
>> /etc/sudoers: syntax error near line 47 <<<
>> /etc/sudoers: syntax error near line 48 <<<
>> /etc/sudoers: syntax error near line 49 <<< 
sudo: parse error in /etc/sudoers near line 36    
sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin

Should I go get the box from the attic and try pkexec visudo or is something else wrong here?

  • AFAIK pkexec only allows this for a local user (not an SSH remote user) - so yes it should work from the attic – steeldriver Jul 17 '16 at 11:29
  • Either get the box, or get the drive, mount it in another computer and edit sudoers to suit. Depends on whats easiest. – vidarlo Jun 19 '18 at 23:27
  • @steeldriverIt It just worked to me as a remote user. JFYI. – php-coder Feb 6 '19 at 16:47

I ran into this problem also and with some digging, found a working solution. The original solution is from this github issue for NixOS by EstalillaJ.

  1. Open two ssh sessions to the target server.
  2. In the first session, get the PID of bash by running:

    echo $$

  3. In the second session, start the authentication agent with:

    pkttyagent --process (pid from step 2)

  4. Back in the first session, run:

    pkexec visudo

  5. In the second session, you will get the password prompt. visudo will start in the first session.

  • 3
    Holy shit dude, u saved my life! thx :D – Roger Barretto Jul 31 '18 at 22:01
  • that is crazy, it works perfect! and no need to reboot the system – undefinedman Oct 16 '18 at 18:02
  • Thanks a ton, this really saved me! ⭑ – Frederic Jul 13 '19 at 6:36
  • what if iam using non sudo user – sachin_ur Nov 8 '19 at 6:11
  • In the second session, can't you enter simply pkttyagent --process $$ instead of copying the process ID from the first session? – IkWeetHetOokNiet Nov 15 '19 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.