su stands for switch user and it is a very important command used by Linux users. In fact this command allows users to run commands under other users without changing functionality.
Using su is the best way to switch to the root user allowing you to perform administrative tasks in special cases that cannot be done by normal users.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Linux systems command queries.
In this context, we shall look into how to use the su command in Linux.
The syntax of su command takes the following form:
$ su [options] [username [arguments]]
Some of its [options] is explained below:
Then run the echo $HOME command to check the directory you are in:
$ echo $HOME
Both sudo and su are used to run as root but in different ways. But how are they different? To know this difference, we first need to understand about root privileges and root users. In fact, the root is the maximum authority you can gain, allowing you to do anything with the system. Besides the fact that the root user can install/remove some packages, root privileges also act as an extra layer of security.
The su command represents the highest authority of the root user. su will launch a new shell.
sudo uses a config file (/etc/sudoers) to define the permissions of different users.
After the comparison, we see sudo for users to use their own account to run system commands. su forces the user to share the root password with other users. That's why sudo doesn't start any new shell windows.
This article covers how to use the su command in Linux and the difference between su and sudo. In fact, the su command changes the current user ID to that of the superuser, or another specified user.
su command syntax is:
su [options] [username]
If no username is specified, su defaults to becoming the superuser (root).
options to use with the su command:
How to enable the Root User in Ubuntu ?
To enable the root user account on Ubuntu, use the following command to set a password for it. Bear in mind that Ubuntu recommends against this:
$ sudo passwd root
Sudo will prompt you for your current user account's password before you can set a new password. Use your new password to log in as root from a terminal login prompt or with the su command. You should never run a full graphical environment as the root user – this is a very poor security practice, and many programs will refuse to work.