Why doesn't the 'su' command work in Ubuntu but does in other Linux distros? [duplicate]
When I type the su
command in a terminal I get
su: Authentication failure
Why doesn't this work in Ubuntu? I have tried this command in another Linux distro (Parrot OS) and it does work.
Because in Ubuntu, by default, root has no password.
Without arguments, su
means "switch user to root" and to do that you have to enter root's password, not your own. Unless you give root a password, it doesn't have one, so you can't literally log in as root.
Here's some background:
In the Unix world, there has always been a larger division between regular users and administrators, owing to the multiuser heritage of Unix. The approach taken in Unix is to grant superuser privileges only when needed. To do this, the su and sudo commands are commonly used.
Up until a few years ago, most Linux distributions relied on su for this purpose. su didn't require the configuration that sudo required, and having a root account is traditional in Unix. This introduced a problem. Users were tempted to operate as root unnecessarily. In fact, some users operated their systems as the root user exclusively, since it does away with all those annoying “permission denied” messages. This is how you reduce the security of a Linux system to that of a Windows system. Not a good idea.
When Ubuntu was introduced, its creators took a different tack. By default, Ubuntu disables logins to the root account (by failing to set a password for the account), and instead uses sudo to grant superuser privileges. The initial user account is granted full access to superuser privileges via sudo and may grant similar powers to subsequent user accounts.
~ The Linux Command Line
You can use su
to switch user, if you know the password of the user to switch to, for example, I can su pixie
to log in as my backup user.
Normally though, you should use sudo
and your own password to authenticate, or to start a root shell, use sudo -i
That is because in the other distros when installing them they usually will prompt you to set a root
password as well as a user account password. Ubuntu does not ask for the root
password during setup, only a user account password of a user that will have sudo
access leaving the root
account disabled in Ubuntu. If you want to have this enabled, set a password for the root
account that will enable the root
account allowing for the su
command to work.
sudo passwd root
Hope this helps!
Briefly
Root account is disabled by default in Ubuntu, hence doesn't have password set, so it causes that authentication failure
To become root in Ubuntu, you can use this
sudo -i
By default, su
has no password. When you run that command, you're trying to log into the hidden root
account on your machine. I'm going to assume that Parrot OS either uses the root
account or sets its password to yours, because otherwise it wouldn't work.
If you want to use su
, then you can run sudo passwd root
and set the password you want to use to log in with su
. This will also enable the root user as a full account user, however, so I don't recommend it.
Instead, when you need persistent root privileges in that shell, use sudo su
. This will allow you to become root by using your own account and password. sudo -i
will have the same effect (and people will recommend you use this instead).