How can I sudo on a new Ubuntu 22.04 installation?

Thread Starter

WBahn

Joined Mar 31, 2012
29,841
Be forewarned, I have extremely limited Linux experience and none of it recent.

I just installed VirtualBox 7 (on a Win11 machine) and then installed Ubuntu 22.04.2 using the directions found here:

On page 2 of the directions, it states to change the default username and password because the default supposedly creates an account without sudo rights. So I change both -- let's say to Fred and Fred123 (clearly these are bogus).

The install went very smoothly. But when I open a terminal window and try to sudo anything, it tells me, "Fred is not in the sudoers file. This incident will be reported."

So it would appear that changing them from the default still resulted in the creation of account without sudo rights.

Every place I look tells me to use sudo in order to add my account to the sudoers file. Duh. Hello!

They also say that the initial root account has no password. So one would think that maybe the trick is to log in as root and make the changes (and change root's password, although given what this machine will be used for, I don't really care).

But no dice. If I either try to use su or logout and login as root, I get an authentication failure.

So, any guidance on how to resolve this would be much appreciated. If I have to, I'm willing to reinstall Ubuntu, though all I have is the .iso file in a folder, I do not have a way to burn a DVD.

Many thanks for any help.
 

joeyd999

Joined Jun 6, 2011
5,162
Ha. Been trying to reply for the last 12 hours, but got browser error.

Something is wrong with your installation. There should be no root login. The username you gave during installation should be your initial sudoer.

Are you sure you are not rebooting into the Live CD attached to the virtual machine?

In ubuntu, the sudoers are members of the group sudo. It is also useful to be a member of the adm group to have read access to log files.

CLI command:

usermod -a -G groupname username

as superuser.
 

joeyd999

Joined Jun 6, 2011
5,162
I know it's by default to provide security but I never use sudo and login in as 'real' root. because I'm always doing things that require superuser access. If something needs to be userland I keep it that way and usually don't allow sudo for regular users.

https://networksynapse.net/development/you-do-not-need-sudo-so-stop-using-it/

https://linuxize.com/post/how-to-enable-and-disable-root-user-account-in-ubuntu/
This is why everyone hates Linux: too many different ways to achieve the same result.

For noobs, I stick with stock and try not to complicate things.

In this particular instance, iron-clad security is not all that big of an issue. I'm sure @WBahn will be happy just getting some packages installed so he can be a user instead of an administrator.

And, besides, I'll bet he knows how to choose a strong password.
 
Last edited:

joeyd999

Joined Jun 6, 2011
5,162
Once you add yourself to the desired groups, you'll need to log out and back in. No need to reboot.

You can test your group membership with the CLI command:

$ groups
 

Thread Starter

WBahn

Joined Mar 31, 2012
29,841
I know it's by default to provide security but I never use sudo and login in as 'real' root. because I'm always doing things that require superuser access. If something needs to be userland I keep it that way and usually don't allow sudo for regular users.

https://networksynapse.net/development/you-do-not-need-sudo-so-stop-using-it/

https://linuxize.com/post/how-to-enable-and-disable-root-user-account-in-ubuntu/
Those do me no good. Even if I was willing to, or wanted to, login as root when needed, I can't. The root account is disabled. To enable it, I need to use sudo in order to change the password. I can't sudo, because my user account doesn't have sudo rights. To give it sudo rights, I either have to login as root or I have to sudo from my user account.
 

Thread Starter

WBahn

Joined Mar 31, 2012
29,841
Ha. Been trying to reply for the last 12 hours, but got browser error.

Something is wrong with your installation. There should be no root login. The username you gave during installation should be your initial sudoer.

Are you sure you are not rebooting into the Live CD attached to the virtual machine?

In ubuntu, the sudoers are members of the group sudo. It is also useful to be a member of the adm group to have read access to log files.

CLI command:

usermod -a -G groupname username

as superuser.
But how do I use usermod to do that without already having sudo rights? When I try it, I get "Permission denied." "cannot lock /etx/password; try again later". Though it seems the problem should be that it can't unlock the file.

I don't know that there is a root login. When I'm logged out and am at the login screen, the only user it shows is fred. If I try to login as root by clicking the "Not listed?" link, when I enter a password (either a blank password or a random password) I get the message "Sorry, password authentication didn't work. Try again".

But, I think that the account itself is there, because of a behavioral artifact. If I try to login to Fred with a bogus password, I get an identical response. It takes about two seconds for it to think and then it displays the failure message for about two seconds before it disappears and leaves me at the password entry screen. But if I try to login to a random user account that doesn't exist, say sue, It takes about two seconds to think and then takes me right back to the original login screen where Fred is listed. It appears that it displays a message in between, but it flashes so fast that I can't tell if it is the same one or not. This behavior would seem to be undesirable since a failed login attempt shouldn't leak any information about whether the account exists.

I'm definitely not logging into any Live CD since there isn't one. I have an iso image in a folder on the machine and am directing VirtualBox 7 to that image in order to do the install.
 
Last edited:

Thread Starter

WBahn

Joined Mar 31, 2012
29,841
Once you add yourself to the desired groups, you'll need to log out and back in. No need to reboot.

You can test your group membership with the CLI command:

$ groups
Fred is a member of the following groups: {fred, vboxsf)
 

xox

Joined Sep 8, 2017
838
Try doing a fresh install? At first, just keep the default username and password as-is. Then:

Code:
sudo passwd root
That should allow you to set the root password. Finally, enable the account with:

Code:
sudo passwd -u root
From there you should of course be able to change your non-root username and password.
 

nsaspook

Joined Aug 27, 2009
12,749
Those do me no good. Even if I was willing to, or wanted to, login as root when needed, I can't. The root account is disabled. To enable it, I need to use sudo in order to change the password. I can't sudo, because my user account doesn't have sudo rights. To give it sudo rights, I either have to login as root or I have to sudo from my user account.
Sounds like the best thing is to do a complete reinstall but this time don't change the default user name, only the password so the user with have a valid UID, GID for the sudo access system. IMO you always want a valid and usable root account because if you need to boot single user recovery mode it will ask for a root password on most Linux systems.
 

joeyd999

Joined Jun 6, 2011
5,162
Sounds like the best thing is to do a complete reinstall but this time don't change the default user name, only the password so the user with have a valid UID, GID for the sudo access system. IMO you always want a valid and usable root account because if you need to boot single user recovery mode it will ask for a root password on most Linux systems.
If I need to break in, I just reboot to a live install, mount the root partition, and make whatever changes I need.

I usually don't allow a root user to log in -- especially via ssh on a world-connected box. At worst, I'll allow root access via private key instead of password.
 

Ya’akov

Joined Jan 27, 2019
8,973
It depends on the system. I don't allow for single user access to a shell prompt without a valid root password.
https://sleeplessbeastie.eu/2014/05/01/how-to-access-single-user-mode-without-password/
HIs plain old Ubuntu installation should. But I don’t know for certain because I don’t use Ubuntu, I use Debian.

He could also boot into a live installer of any version and edit passwd and shadow directly (assuming that Unbuntu is still using files for auth.

I think @joeyd999 said something like that earlier.
 

Thread Starter

WBahn

Joined Mar 31, 2012
29,841
So I did a fresh install and now I'm a member of nine groups (including sudo), but not a member of vboxsf. I have no idea what the significance of that might be.
 

joeyd999

Joined Jun 6, 2011
5,162
vboxsf -- VirtualBox Shared Folders group. Not necessary unless you're sharing files with the host OS via VirtualBox shared folders.
 

Thread Starter

WBahn

Joined Mar 31, 2012
29,841
vboxsf -- VirtualBox Shared Folders group. Not necessary unless you're sharing files with the host OS via VirtualBox shared folders.
Thanks. That sounds like it might be useful, but not something that I can't live without for now. I imagine I can set that up later if I decide I really want it.
 
Top