The root account on a Linux-based computer is an account with full permissions. You will need to use the root account to execute certain commands, especially those that affect system files. Since the root account can affect the computer as a whole, it's best to use this account only as needed, rather than using it in place of a regular account. In this way, you reduce the risk of "accidents" damaging important system files.
Step
Method 1 of 4: Accessing root from Terminal
Step 1. Open Terminal by pressing Ctrl+Alt+T
Most Linux distributions allow you to access the Terminal with this shortcut.
Step 2. Enter the command su - and press Enter
The computer will try to access the super user account. You can use this command to log into any account on the system, but if you don't specify an account name, you'll be logged into the root account.
Step 3. After typing the command su - and pressing Enter, enter the root password if prompted
If you receive an authentication error, your root account may be locked. Read the next steps to open an account
Step 4. Check the command line
When logged in as root, the command line will end in # instead of $.
Step 5. Enter the command that requires root access
After using the su - command to log in as root, you can use any command that requires root access. The su command is saved until the end of the session so you don't have to enter your root password every time you run the command.
Step 6. Consider using the sudo command instead of su -
The sudo (super user do) command allows you to run a command as root. sudo is highly recommended for most Linux users because by using sudo, root access is not saved, and the user does not need to know the root password. Users will only be asked to enter their respective passwords.
- Enter the sudo command and press Enter (eg sudo ifconfig). After that, enter your account password when prompted.
- The sudo command is the recommended command for root access on distributions that lock the root account, such as Ubuntu. Even if the root account is locked, you can still use sudo.
- The sudo command can only be used by users with Administrator privileges. Access rights can be granted and revoked by editing the /etc/sudoers file.
Method 2 of 4: Unlocking Root Access (Ubuntu)
Step 1. Open root access in Ubuntu Linux
Ubuntu and various other Linux distributions lock the root account so that it cannot be accessed by normal users. This step is done because a root account is generally not required. Instead, the distribution allows root access via the sudo command (described in the previous step). Once the root account is unlocked, you can log in as root.
Step 2. Open Terminal by pressing Ctrl+Alt+T
Step 3. Enter sudo passwd root and press Enter
Enter your account password when prompted.
Step 4. Create a password for the root account, and re-enter it to confirm it
After setting the password, the root account will be active.
Step 5. Lock the root account with the following command:
sudo passwd -dl root
Method 3 of 4: Log in to System as root
Step 1. Consider using another way to access the root account
Accessing the root account directly for daily use is not recommended as you may run malicious commands. Only use the root account to perform emergency system repairs, such as recovering an unusable drive or restoring an inaccessible account.
- Using the command sudo or su, instead of logging in as root, allows you to take advantage of the root account without experiencing the harm. Both commands will make you think twice before using any particular command.
- Certain Linux distributions, such as Ubuntu, lock the root account until you manually unlock it. Apart from preventing users from tampering with the system with the root account, this step also protects the system from hackers because hackers will generally target the root account first when hacking the system. If the root account is locked, hackers cannot access the account. Read the previous steps to access root account in Ubuntu.
Step 2. Enter root as the username when prompted to log into the Linux system
If the root account is unlocked and you know the password of the account, you can log in as root directly.
If you need root access to run certain commands, use some of the steps above first
Step 3. After entering root as the username, enter the root password when prompted
- On many systems, you can access root with the password "password".
- If you forget or don't know your root password, read the next steps to find out how to reset your password.
- If you are using Ubuntu, the root account is locked and cannot be used until you manually unlock it.
Step 4. Avoid running complex programs while using the root account
The program you are running may damage the system if accessed with the root account. Instead of using the root account, run commands that require administrator access with the sudo or su commands.
Method 4 of 4: Recovering Root or Administrator Password
Step 1. Reset root password if you can't remember it
If you don't remember your root password and user account, you may need to access recovery mode to change both passwords. If you know your user account password and want to change the root password, use the command sudo passwd root. After that, enter your account password and a new password for the root account.
Step 2. Restart your computer, then press Shift after the BIOS screen appears to open the GRUB menu
You may need to repeat this step several times before the GRUB menu appears
Step 3. Select the first (recovery mode) entry in the list that appears
Your Linux distribution's recovery menu will appear on the screen.
Step 4. Select the root option from the menu
A terminal with root privileges will load.
Step 5. Open a drive with read-write privileges
When you use Linux recovery mode, your drive is read only. Use the following command to enable write permissions:
mount -rw -o remount /
Step 6. After logging in as root and changing drive permissions, create a new password for the locked account
- Enter the command passwdAccountName and press Enter. If you want to change the root password, enter passwd root.
- Enter the new password twice when prompted.
Step 7. Restart the computer after resetting the password
After the computer restarts, you can use the computer as before with the password you set earlier.
Warning
- Only use the root account if absolutely necessary. Log out of the account when you are done using it.
- Give the root password only to users you trust and really need it.