2

Today I run into ironic and awful situation - I have broken sudo command. I don't have physical connection to the machine. The only way I can access server is via SSH.

So firstly I connected as "client_user" to server via ssh and then switched to root with sudo su root. I used vim command for editing /etc/sudoers and took down "#" character from include line. That gave me syntax error.

The worst part is that I don't have root user password. I have google for over 4 hours and have tried:

  • mv & cp sudoers, but for that I need sudo rights

  • pkexec visudo but it's not available on debian or simply just not installed. To install apps we need sudo.

  • pktyagent command with 2 different sessions

  • su root command but it's not usable without password

People on the internet recommended to use recovery mode but as far as I am concerned it is not possible using SSH.

The only possible solution which caught my eye was to use root's active cron job to chown sudoers file. But not sure if that possible without sudo. Also heard about adding script to ,,Tasks Scheduler" for changing sudoers file.

Maybe somebody have any ideas?

Adding photo to make everything more clear. enter image description here

8
  • 9
    I know this won't help you, but for future users (and future you): never edit /etc/sudoers directly! ALWAYS use visudo, that's what it's for.
    – terdon
    CommentedNov 6, 2020 at 18:35
  • Yes, I deffinitely have learned my lesson now - to use visudo in the future. It checks syntax.CommentedNov 6, 2020 at 18:37
  • 2
    If anybody is scared of the name, visudo invokes $EDITOR (there are a couple of other environment variables that have influence, but if they are set, the user probably knows what he's doing) and not vi, so there's no reason not to use visudo!CommentedNov 6, 2020 at 20:06
  • 1
    In general it's possible to create a syntactically valid sudoers file that will not grant you sudo access. So aside from using visudo you should keep an additional root shell open. Exit this emergency shell only after you confirm you can use sudo (especially sudo visudo) after the changes. In case the connection breaks it's good to have this emergency shell inside tmux (or screen) which runs for your regular user, so you can reconnect as the regular user, reattach to tmux and the emergency shell is still there. Such shell can be a life-saver.CommentedNov 6, 2020 at 21:20
  • 1
    "I connected as root to server via ssh" do you really mean you were able to login directly as root? If so there's no problemCommentedNov 6, 2020 at 21:37

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.