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)!
1 Answers
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 appendinit=/bin/shto it. This will replace yourinitsystem temporarily by your system's shell and sinceinitis 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
vimcalledvim.tiny. - In the particular case of the
sudoersfile, you should edit it usingvisudobecause 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 thesudoersfile. - With enabled root access use
rebootto 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:
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.
- 38,849
- 7
- 107
- 143
-
1Is `usermod -aG
sudo` an exposure of some kind? (As I recall Debuan has `%sudo ALL = (ALL) ALL`). – jthill Nov 13 '13 at 18:36 -
@jthill You're right, Debian does have that line in the `sudoers` file; the problem is, to use `usermod` the OP would need to have root access, and if they did, I don't think they would've needed this question. – Joseph R. Nov 13 '13 at 18:43
-
Don't misunderstand, I wasn't disagreeing w/ `init=/bin/sh`, came here to be sure that was mentioned, only that not being in sudoers was the original complaint and sudo is like bash, pretty much everyone assumes familiarity -- and I have heard recommendations against enabling root at all. – jthill Nov 13 '13 at 18:51
-
@jthill No misunderstandings here, I agree with your comment: it is indeed the easiest way to gain sudo access. I'm just saying that it's likely impossible in the OP's case. – Joseph R. Nov 13 '13 at 18:52
-
@jthill Oh. Sorry, one of my brain's light bulbs needs fixing :) Good point. I'll edit the answer accordingly. – Joseph R. Nov 13 '13 at 18:54
-
From the `usermod` command, I get `user 'sudo' does not exist` – IQAndreas Dec 27 '14 at 13:59
-
Found the problem, the arguments are reversed. The command needs to be `usermod -aG sudo
` – IQAndreas Dec 27 '14 at 14:00