0

I accidentally command the root admin and sudo in sudo visduo file.

Now with current user it is not rolling it back because I can't access it any more.

File does not get opened with command sudo visudo It says: user is not in sudoers file.

While if I access it by nano /etc/sudoers It says permission denied when I try to save the file again.

$sudo cat /etc/sudoers
...
# User privilege Information

#root ALL=(ALL) ALL

#...
#%sudo ALL=(ALL) ALL
#
#includedir /etc/sudoers.d

#Members of the admin group may gain root privileges
#%admin ALL=(ALL) ALL
#
10
  • 6
    Login as root and fix it. Failing that, you'll need to boot into single-user mode and adjust it that way.
    – Nathan C
    Commented Oct 30, 2014 at 13:29
  • I am using root user.
    – Sarz
    Commented Oct 30, 2014 at 13:37
  • 1
    Then you don't need sudo. Just run visudo normally. Or, even vi /etc/sudoers. If you messed up permissions, use chmod 660 /etc/sudoers first.
    – Nathan C
    Commented Oct 30, 2014 at 13:42
  • it says Permission denied :(
    – Sarz
    Commented Oct 30, 2014 at 13:43
  • Time for single user mode. Depending on your distro, the instructions are different, so look that up and you should be able to access it.
    – Nathan C
    Commented Oct 30, 2014 at 13:44

2 Answers 2

0

Since you can login with the 'root' user, you only need to do this:

chmod 644 /etc/sudoers

This will allow the 'root' user to modify the /etc/sudoers file. After this, you only need to:

nano /etc/sudoers

and save your changes.

8
  • It says "chmod: changing permissions of `/etc/sudoers': Operation not permitted" :(
    – Sarz
    Commented Oct 31, 2014 at 6:15
  • Tell me the result of these two commands: 'whoami' and 'id root'
    – gmarintes
    Commented Oct 31, 2014 at 6:17
  • Actually its root user is off and we were accessing by doing 'sudo bash' from user softAgent. whoami = softagent and id root = uid=0(root) gid=0(root) groups=0(root)
    – Sarz
    Commented Oct 31, 2014 at 6:27
  • 2
    Like what the others said, you'll need to login as root user for you fix this.
    – gmarintes
    Commented Oct 31, 2014 at 6:36
  • My softagent is with same privileges as root I just logged into recovery mode although it is just read-only mode, but i can not run any of sudo command
    – Sarz
    Commented Oct 31, 2014 at 6:39
0

Use shellshock to send an echo to /etc/passwd (or sudoers(But, I don't know how difficult it would be to Remove a comment. I thought echo could only add)) to create a user with identifier 0. unlimited access root or not. How one would create such a carefully crafted command is beyond me.

Alternatively, it could very well be possible to chroot into it from a live environment and edit sudoers from there. Not sure because yo said that even root couldn't get in. I don't know how catastrophic it would be to env x='() { :;}; rm /etc/passwd' bash -c "You've done it now" I also don't know if your distro provides the means to cp /etc/skel/sudoers /etc/sudoers

Very similar to this. The solution could be there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .