Change user or substitute user in command line terminal using Linux su command

The Linux su command is often use when performing administrative task in Linux system. Linux system administrator or Linux user do not use root as a personal account. When a certain task needs root privilege, then the Linux su command, which is used to substitute user, become useful. The Linux su command allows user to switch to other UID and GID from the command line terminal. Here is a description and synopsis from su manual page:

NAME
       su - change user ID or become superuser

SYNOPSIS
       su [options] [username]

When invoking su command with no option, user are switching to root by default. Here is the example:

kkcjlab@ubuntu-server:~$ su
Password: 
su: Authentication failure
kkcjlab@ubuntu-server:~$

You need to provide the correct password for the user account you are switching to. You'll get the root environment when you successfully enter the correct password as in the su command example below:

kkcjlab@ubuntu-server:~$ su
Password: 
root@ubuntu-server:/home/kkcjlab#

If we want to substitute user or switch to other user id, use Linux su command with username switch. Here is the example on how to use su command to substitute user in Linux command line terminal:

root@ubuntu-server:/home/kkcjlab# su jimi
jimi@ubuntu-server:/home/kkcjlab$

You don't have to provide user password if you are root. If you are using your personal account (normal user account), you have to provide the correct password for the user account that you are switching to. Here is the su command example if you are switching to another user from a normal user account:

kkcjlab@ubuntu-server:~$ su jimi
Password: 
jimi@ubuntu-server:/home/kkcjlab$

You can use 'exit' command or simply press 'Ctrl+D' combination keys to switch back to your account when you finished doing your job. Here is the example on how to end session and return to your user account:

jimi@ubuntu-server:/home/kkcjlab$ exit
kkcjlab@ubuntu-server:~$ 

That's all.

You can also use "su -" ,

You can also use "su -" , the su dash.
It will make change the home directory to the home directory of the new user, and also, modify any environment variables.
I think it is safer to use this.

devanoair's last blog post... Linksys PLE300 PowerLine AV Network Adapter