You need root access (also known as superuser) to run administrative programs on Linux. Generally, Linux distributions provide a separate root account, but that account is locked on Ubuntu Linux by default for security. To run a command with root access, use sudo.
Step
Method 1 of 2: Running Root Commands with Sudo
Step 1. Press Ctrl+Alt+T to open a Terminal window
Unlike other Linux distributions, Ubuntu locks the root account by default. Therefore, you cannot use the su command to run a root terminal. To replace su, use sudo.
Step 2. Enter sudo at the beginning of the command
sudo, short for super user do, lets you run commands on Linux as root.
- For example, the command sudo /etc/init.d/networking stop will stop network services, and sudo adduser will add a new user to the system. The two commands above actually have to be run as root.
- You will be prompted for the account password before sudo runs the command. Linux stores your password for 15 minutes so you don't have to type it every time you run a command.
Step 3. Use the gksudo command to run programs with a graphical interface that require root access
For security reasons, Ubuntu does not recommend that you use sudo to run programs with a graphical interface. Instead, start a command to open a graphical interface program with gksudo.
- For example, use the command gksudo gedit /etc/fstab to open the fstab file in GEdit, a text-editing program with a graphical interface.
- If you are using KDE, replace gksudo with kdesudo.
Step 4. Simulate root access with the command sudo –i if you need root shell access to run certain scripts
The command lets you access the superuser account and environment variables.
- Enter the command sudo passwd root to create a password and activate the root account. Remember the password.
- Enter sudo -i, then provide the root password when prompted.
- The command line will change from $ to #. The # symbol indicates that you have root access.
Step 5. Give sudo access to users who don't have access yet by adding them to the sudo group
Use the command usermod -aG sudo username, and replace "username" with the name of the user you want to grant access to.
Method 2 of 2: Enabling Root Account
Step 1. Press Ctrl+Alt+T to open a Terminal window
Unlike other Linux distributions, Ubuntu locks the root account by default for security. To safely run commands with root privileges, use
sudo
or
gksudo
. If you really need to access the root account, for example for an important program that only one user has access to, you can enable the root account with a simple command.
Enabling the root account may harm the system. Ubuntu does not recommend that you enable the root account
Step 2. Enter the command sudo passwd root and press Enter
You will be asked to enter a new password for the root account. Don't forget this password.
Step 3. Enter the password, then press Enter
Step 4. Repeat the password when prompted, then press Enter
Now, the root account is password protected and accessible.
Step 5. Enter su - and press Enter
Enter the root password when prompted to access the account.
To disable the root account, use the command sudo passwd -dl root
Tips
- Wherever possible, avoid using the root account directly. You can run almost any command with root privileges via sudo or gksudo.
- You can also use the command sudo –i to access other user accounts on the system. For example, to access the user "ayu", use the command sudo –I ayu and enter your password (instead of Ayu's).