4

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)!

7

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:

  1. From the bootloader prompt, navigate to the regular entry you boot from.
  2. Instead of pressing Enter press e to first edit the kernel command line parameters
  3. 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/sh to it. This will replace your init system temporarily by your system's shell and since init is started by root, this will be a root shell.
  4. Press CTRL+X to boot the modified entry
  5. 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.
  6. You can enable root access by entering a password for root: use the passwd command for this.
  7. 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 vim called vim.tiny.
  8. In the particular case of the sudoers file, you should edit it using visudo 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 the sudoers file.
  9. With enabled root access use reboot to 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.

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.

  • 1
    Is usermod -aG <userid> 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.