r/debian • u/pannic9 • Jun 28 '25
Problem using sudo in Debian VM
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?
12
4
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
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
2
u/TheBlueElvryn Jun 29 '25
Open a terminal and :
su
Enter the password
nano /etc/sudoers
Scroll down to find" root All(all:all) " copy it and paste it under it then replace the word "root" with your user name
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
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
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
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
1
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
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/binpart? It's a waste of time, just dosu.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 dosu root, orsudo suto switch to the root user, which has/sbinin 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
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
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
0
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...
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.