Accidentally removed my gnome desktop and am stuck in tty1. Trying to reinstall the desktop and keep getting the error "user is not in the sudoers file". Having trouble adding my user, new to debian and am not sure how to correctly open/edit sudoers from tty1 (or really how to edit files from cmd line for that matter if someone could please lend some specifics)!
I can’t access the root account anymore: user is not in the sudoers file
rootsudosystem-recovery
Best Answer
To edit the
sudoers
file, you first need to be root. My guess, from this question, is that you have not enabled root access for your installation, correct?If that's the case, you need to change that:
linux
, go to its end and appendinit=/bin/sh
to it. This will replace yourinit
system temporarily by your system's shell and sinceinit
is started by root, this will be a root shell.mount -o remount,rw /
to do that.passwd
command for this.vim
calledvim.tiny
.sudoers
file, you should edit it usingvisudo
because it does syntax checking for you before writing the file. If you follow this procedure for enabling the root account, you shouldn't need to add your regular user to thesudoers
file.reboot
to boot normally (the edits in step 3 are temporary and vanish on reboot). When faced withtty1
, you can then log in as root (with the password you created in step 6) and reinstall your desktop.Note
As noted by @jthill in the comments below, you may opt out of enabling root access altogether and grant your regular user sudo (this is arguably more secure). In that case, instead of using
passwd
to give your root account a password, you should use:This is likely to only work on Debian (and its derivatives) as it has the entry:
which basically grants unfettered sudo access to all members of the
sudo
group. Theusermod
command above is meant to add your regular user to thesudo
group. The presence of the above line is not guaranteed for other distros. Some distros use a group calledwheel
instead ofsudo
for that purpose, for example.