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)!
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:
- From the bootloader prompt, navigate to the regular entry you boot from.
- Instead of pressing Enter press e to first edit the kernel command line parameters
- In the editor that opens, use the arrow keys to find the line that starts with
linux, go to its end and append
init=/bin/shto it. This will replace your
initsystem temporarily by your system's shell and since
initis started by root, this will be a root shell.
- Press CTRL+X to boot the modified entry
- Once you have a root shell, you usually need to remount the root filesystem read/write instead of read-only. Enter the command
mount -o remount,rw /to do that.
- You can enable root access by entering a password for root: use the
passwdcommand for this.
- Usually you edit files in text mode using a text mode editor like vim or emacs, neither of which Debian ships by default. What Debian does ship by default is a lightweight version of
- In the particular case of the
sudoersfile, you should edit it using
visudobecause 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 the
- With enabled root access use
rebootto boot normally (the edits in step 3 are temporary and vanish on reboot). When faced with
tty1, you can then log in as root (with the password you created in step 6) and reinstall your desktop.
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:
usermod -aG regular_user_name sudo
This is likely to only work on Debian (and its derivatives) as it has the entry:
%sudo ALL = (ALL) ALL
which basically grants unfettered sudo access to all members of the
sudo group. The
usermod command above is meant to add your regular user to the
sudo group. The presence of the above line is not guaranteed for other distros. Some distros use a group called
wheel instead of
sudo for that purpose, for example.