r/debian • • Jun 28 '25

Problem using sudo in Debian VM

Post image

I installed Debian in a VirtualBox VM, with the first ISO that appears on the official website. I just installed it and went to Virtualbox to run it. For some reason, sudo doesn't work. I did some basic research to fix it, but found nothing. How do I fix it? And why did this happen? Is it more normal than it seems?

4 Upvotes

68 comments sorted by

92

u/[deleted] Jun 28 '25

Unlike Ubuntu, Debian does not set up the default user as a sudo user by default.

You will have to type 'su', enter the root password, access the root # shell, and then:

usermod vboxuser -a -G sudo

And then edit /etc/sudoers (IIRC) to uncomment the line about giving sudo to anyone with sudo group membership.

6

u/degaart Jun 28 '25

You have to log out after doing this or the user won’t properly inherit its new group membership

2

u/DeepDayze Jun 28 '25

Absolutely right as being added or removed from a group does not take effect till user logs out or the system is rebooted.

1

u/roelschroeven Jun 28 '25

Well strictly speaking it's logging in that does the job, not logging out. When starting a new session with a new log in (using ssh, for example, or on a new console), the change in group membership takes effect (but only in that new session).

So in general you indeed log out an then back in again, and it doesn't really matter what part of that process makes the group membership have effect.

1

u/neoh4x0r Jun 30 '25 edited Jun 30 '25

You have to log out after doing this or the user won’t properly inherit its new group membership

The only reason someone would need to fully logout is so that the changes to the user's group membership would take effect globally.

However, a user could run su - USERNAME in a terminal to reload the user's group memberhips, within that session, without needing fully logout.

3

u/CLM1919 Jun 28 '25

+1 perfect answer.

There are ways do to it through the GUI, depending on your desktop environment, if OP is interested.

Scroll down to GUI directions at linuxjournal

4

u/AmiSimonMC Jun 28 '25

Do not edit /etc/sudoers !! Use visudo as root or EDITOR=/usr/bin/[your editor] visudo for custom editor

1

u/charles25565 Jun 29 '25

Don't think an absolute path is required.

1

u/AmiSimonMC Jun 29 '25

Probably not but can't hurt

2

u/BCMM Jun 28 '25

su -, not plain su, or you get confusing environment issues.

1

u/2204happy Jun 29 '25

run visudo to edit /etc/sudoers, do not edit it directly!!

1

u/[deleted] Jun 29 '25

But then I'd need to use vi

1

u/2204happy Jun 30 '25

Yes, just for this one thing.

1

u/[deleted] Jun 30 '25

Impossible.

2

u/2204happy Jun 30 '25

iirc there's a way to set visudo to run something else instead if you really do care, but don't edit it directly, that's a bad idea.

64

u/[deleted] Jun 28 '25

[removed] — view removed comment

12

u/DansPhotos Jun 28 '25

Leaving the root password empty was exactly what I did when I installed Trixie on my laptop, and my user is part of sudoers.

3

u/[deleted] Jun 28 '25

OP prob used the auto install feature

2

u/Major-Management-518 Jun 28 '25

Isn't this a security issue?

1

u/Yugen42 Jun 28 '25

Depends on the context and threat model.

1

u/Jutboy Jun 28 '25

No. Either way you are putting root access behind one password.

7

u/[deleted] Jun 28 '25

[removed] — view removed comment

1

u/Major-Management-518 Jun 28 '25

I'm not sure if this is sarcasm.

12

u/NormalAmountOfLimes Jun 28 '25

This is easily googleable

4

u/[deleted] Jun 28 '25

Standard, in my experience. You need to add yourself (if non-root user) to that group when logged in as root.

7

u/iphxne Jun 28 '25

they should really add a checkbox in the installer for this, it always catches me off guard.

2

u/[deleted] Jun 28 '25

Access root with su -, and do sudo visudo, then go down the lines and you will see an example of how to add your user there.

2

u/Brufar_308 Jun 28 '25

Check the Debian wiki for instructions.

https://wiki.debian.org/sudo/

2

u/TheBlueElvryn Jun 29 '25

Open a terminal and :

  1. su

  2. Enter the password

  3. nano /etc/sudoers

  4. Scroll down to find" root All(all:all) " copy it and paste it under it then replace the word "root" with your user name

  5. Press ctrl o then press enter then press ctrl x

2

u/RodrigoZimmermann Jun 29 '25

The message already says what the problem is. It is the Debian default not to use sudo.

You must add the user to the group of users with permission to use sudo.

3

u/CardOk755 Jun 29 '25

"for some reason sudo doesn't work"

I am struggling here.

Can you read?

2

u/iamemhn Jun 28 '25

Did you read the Installation Guide thoroughly? This section in particular

https://www.debian.org/releases/stable/i386/ch06s03.en.html#di-user-setup

You set a password for root so the system is behaving exactly as documented.

If you set up a root password, then you need to become root using su -, and add users to the sudo group as needed.

2

u/[deleted] Jun 28 '25

For sudo to work out of the box on Debian, you have to leave the root password blank during install.

You’ll have to add that user to the sudoers file under the root line. Have it say the same thing except change root to the user name.

1

u/[deleted] Jun 29 '25

Debian installer is a bit confusing and doesn't add your default user to the sudo group if you set password for the root. Google about user and group management and add manually.

1

u/acme65 Jun 30 '25

prnt scrn

1

u/jsantosrocha Jun 30 '25

Canonical moment of the debian user coming from another distro.

1

u/elalemanpaisa Jul 01 '25

Tell us more. Did you install it? Did you set up a root account? If so sudo isn’t setup

~ su -

Visudo (setting up the wheel group for sudo usage as you like)

usermod -aG wheel vboxuser

exit

~ exit

Relogin

1

u/[deleted] Jul 02 '25

First, type: su - Then type: usermod vboxuser -a -G sudo Finally reset vbox.

1

u/HeavyAd349 Jul 02 '25

That happens when you added a password to root in the installation. And after, an user. That user doesnt have root access.

1

u/Obscure-Oracle Jun 28 '25

When you install, leave the super user account fields empty (the installer does say) then on the next page put your username and password and it will install with your account as sudo like you're probably used to with other distros.

1

u/LuisG8 Jun 28 '25

You created a super user account when installing, that's the password to use 'sudo'. To avoid this, skip super user account creation, and the next step the installer will ask you to create a regular account, which will then be root user by default.

-1

u/korogani Jun 28 '25

Use '/usr/bin/su' instead of 'sudo'

4

u/TheShredder9 Debian Stable Jun 28 '25

Why the /usr/bin part? It's a waste of time, just do su.

0

u/Last-Assistant-2734 Jun 28 '25

/usr/bin might not be in the PATH, for some reason or another.

3

u/TheShredder9 Debian Stable Jun 28 '25

Should always be, on any distro out there. Without that, you won't be able to run any command.

Debian stores some binaries in /usr/sbin, to which only the root user has access (if you configured it during install), so you have to do su root, or sudo su to switch to the root user, which has /sbin in its PATH.

1

u/roelschroeven Jun 28 '25

Debian stores some binaries in /usr/sbin, to which only the root user has access (if you configured it during install), so you have to do su root, or sudo su to switch to the root user, which has /sbin in its PATH.

That's not entirely correct. All users have access to the binaries in /usr/sbin; it's just that by default it's not in their PATH. Any user can run them by specifying the full path. Using su or sudo is way overkill.

Unless of course the operation you want to do needs root access, then you do need su or sudo. But that is completely independent of the directory the binary is in.

1

u/Last-Assistant-2734 Jun 28 '25

Should always be, on any distro out there

It depends. In "normal" installations it quite often is.

Without that, you won't be able to run any command.

Well, you certainly will be able to, as mentioned, by using the absolute path to command.

1

u/TheShredder9 Debian Stable Jun 28 '25

Any example of an "abnormal" installation where it isn't the case? I'd assume something like LFS.

Good point about using the absolute path though, never considered that. A while back i messed up my PATH, and couldn't run anything, i just chrooted to fix it.

1

u/Last-Assistant-2734 Jun 28 '25

There may be some very minimal shell environments, for example. I've run into that with mentioned Debian. But also on some mobile device platforms.

1

u/roelschroeven Jun 28 '25 edited Jun 28 '25

These days Debian puts all binaries in /usr/bin (except the ones that go in /usr/sbin), so it would be very weird if /usr/bin is not in PATH. If you can run things like ls or cp without having to specify the full path, you can run su as well.

1

u/Last-Assistant-2734 Jun 28 '25 edited Jun 28 '25

I'm pretty sure 'su' is still /bin/su. As well as all shells, and all rudimentary system commands go to /bin and /sbin.

But other than that, it's really uneccessary argue about why would someone use absolute path instead of just the command name, as the absolute path at least just works.

2

u/roelschroeven Jun 28 '25

/bin and /sbin have become symlinks to /usr/bin and /usr/sbin. So you can still access su via /bin/su (and I think that's not going to change), but it's real location is /usr/bin/su. The same goes for other commands.

$ ls -ld /bin /sbin
lrwxrwxrwx 1 root root 7 Mar 25  2024 /bin -> usr/bin/
lrwxrwxrwx 1 root root 8 Mar 25  2024 /sbin -> usr/sbin/

So all of these commands can be used without full path if either /bin or /usr/bin is in PATH.

See https://www.debian.org/releases/bookworm/amd64/release-notes/ch-information.en.html#a-merged-usr-is-now-required and https://wiki.debian.org/UsrMerge

-2

u/korogani Jun 28 '25

What I saw on stackchange, it worked so I didn't question it. Never had a problem with typing an extra 9 characters so I didn't feel the need for a shortcut.

3

u/[deleted] Jun 28 '25

[removed] — view removed comment

0

u/korogani Jun 28 '25

Congrats, you paraphrased another users answer. How about you drop the condescension and try to be original you cretin.

2

u/[deleted] Jun 28 '25

[removed] — view removed comment

0

u/korogani Jun 28 '25

"wrong advice", are you fucking joking? How can it be wrong if it works. A dirty workaround? Sure, that's fair enough but wrong? If you'd actually take a minute to peel your sweaty cum stained fingers away from your phone to try it, you'd see it works.

0

u/[deleted] Jun 28 '25

Just use su instead. A bit different but it'll do the job

0

u/porta-de-pedra Jun 28 '25

Try using the command su root and then type the sudo password.

0

u/Vinicius_Schneider Jun 28 '25

Do "sudo su" then add yourself in the sudo group with "usermod vboxuser -a -G sudo"

-2

u/-viin Jun 28 '25

there are a few posts here explaining that but, lately, I've been mostly using gemini or GPT to help with that... it was a walk in the park to solve this exact same problem via gemini...