When you setup a new Ubuntu or OS X installation a user is generally created for you. On OS X it is whatever username you pick. On Ubuntu (the server version) usually the ubuntu user is created.
The way I understand it, there is also a root user, which you can access via something like sudo su - root, and entering the password of the ubuntu or the user you created, which is part of the administrators group. Once you switch to root I think you can use the passwd command and change root’s password.
But what was root‘s password before that? Does it exist? Is it a random string of numbers and letters? How does the system deal with that?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I can answer only for Ubuntu.
In Ubuntu the root user has a locked password. From passwd man page:
-l, --lock
Lock the password of the named account. This option disables a
password by changing it to a value which matches no possible
encrypted value (it adds a '!' at the beginning of the password).
You can see the ! in /etc/shadow.
A user with a locked account cannot change its password, but root can, without prior entering of the old password.
Method 2
Here’s how to unlock (?) or create an actual root user in OSX:
- System preferences
- Users & Groups
- Login options (click lock and authenticate here)
- Click “Join” (NAS)
- Open Directory Utility
- Click the lock (authenticate again)
- Edit menu -> enable root user
- (Edit menu -> change root password)
Enjoy !
Method 3
As enzotib said, Ubuntu has a root account but it’s locked by default.
Now, about Macs:
As you can probably guess, root (along with all the daemon accounts) doesn’t appear in the “Users & Groups” section of Settings.
Looking at my mac’s /etc/passwd, there is an entry for root, along with a message
Note that this file is consulted directly only when the system is running in single-user mode. At other times this information is provided by Open Directory.
I tried to find the Open Directory user list, without success, but in the configurations there were mentions of explicitly giving root permissions even though they’re implied. I was never prompted for a root password when I first set the machine up, so I’d guess the root account is locked as it is in ubuntu. I didn’t (and don’t really want to) try giving root a password and logging in with it, but you probably could.
The passwd line:
root:*:0:0:System Administrator:/var/root:/bin/sh
The perl command from keith’s comment adds a :0 to the end. No password hash. There’s no shadow file I can find either, I haven’t been able to find them anywhere to check whether root might have a password.
Method 4
The root password on Mac OS X is stored (as mentioned by Kevin) in Open Directory. To confirm the existence of the root user a simple grep is required:
$ grep ^root /etc/passwd root:*:0:0:System Administrator:/var/root:/bin/sh
To read the root password information from Open Directory:
$ dscl localhost -read /Local/Default/Users/root Password Password: * $ dscl localhost -read /Local/Default/Users/root AuthenticationAuthority No such key: AuthenticationAuthority
In the default case (as shown), the root user does not have a password hash set (the account is locked). You can compare this setting with the value in OD for a “normal” user:
$ dscl localhost -read /Local/Default/Users/normaluser Password Password: ******** $ dscl localhost -read /Local/Default/Users/normaluser AuthenticationAuthority AuthenticationAuthority: ;ShadowHash;HASHLIST:<SALTED-SHA512>...#rest of hash data
Method 5
Ubuntu sets up a password for the named user and uses it for superuser (root) level tasks as installing and deleting system wide software and directory and file deletion/execution beyond your home directory. A root account is in fact in place but without an assigned password a bit hidden. Canonical, and Ubuntu usage conventions, in effect discourage you from directly invoking it.
It sets up a named user account rather than setting up a generic “ubuntu” account. That is at least the case with installed systems. A generic “ubuntu” account maybe in place if you use a live CD, I can’t remember, I have not worked with a live CD in a couple of years.
The behavior in MacOsX is actually quite similar. You are asked to set a password, which is invoked each time you attempt to do superuser level tasks such as installing or upgrading software but there is no account named “root”.
Method 6
For Ubuntu:
by default you can access your newly created user account.
To run any command as root you can use
sudo command
then enter your normal password.
The root account is by default locked. To activate root by command line just enter
sudo passwd
then enter your logged in user’s password and then new passwords for root. Now you can log in as root using su
and then enter root’s password.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0