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?
/etc/sudoers
directly! ALWAYS usevisudo
, that's what it's for.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 notvi
, so there's no reason not to usevisudo
!sudoers
file that will not grant yousudo
access. So aside from usingvisudo
you should keep an additional root shell open. Exit this emergency shell only after you confirm you can usesudo
(especiallysudo visudo
) after the changes. In case the connection breaks it's good to have this emergency shell insidetmux
(orscreen
) which runs for your regular user, so you can reconnect as the regular user, reattach totmux
and the emergency shell is still there. Such shell can be a life-saver.