Debian sudo doesn’t work – How to make Sudo work

Debian, by default, creates a root user, and does not configure sudo. During the installation, you will have been asked to enter a root password. You need to use that to enable yourself to become root through sudo. First, run:
su -
This will ask for your root password. Enter that. Next, add yourself to the sudo group:
usermod -aG sudo your_username
Alternatively (Debian-specific), you can also use adduser to add yourself to a group:
adduser your_username sudo
Now log out of the root shell. You will be able to use sudo from now on.
If you don’t know your root password, talk to the person who installed your machine and ask them to give you sudo rights. If that was you and you’ve forgotten it, you can create a new one:
  • Reboot your machine.
  • At the grub boot menu, highlight the “Debian GNU/Linux” option, then hit the e button on your keyboard. This will give you a sort of editor window where you can modify the boot commands.
  • In the editor, search for the line that starts with linux. At the end of that line, add init=/bin/bashDo not change anything else. If you’ve made a mistake, hit the Esc button to go back to the menu and start over.
  • If you now hit ctrl + x, the system will boot to a bash prompt. The normal boot sequence will be completely bypassed, which means (amongst other things) that only the root filesystem will be mounted, and it will be mounted read-only.
  • Run mount -o remount,rw / to remount the filesystem in read-write mode.
  • Run passwd. The system will ask for a new password (twice, to confirm you didn’t enter any typoes).
  • Run mount -o remount,ro / to put the filesystem back in the (safe) read-only mode
  • Run exec /sbin/init. The system will now boot as normal.
Note: doing this on a system that isn’t yours will earn you the (rightly earned) wrath of the system’s owner. Don’t do it without their permission 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *