Switching User in Linux Operating System

Posted on

Switching User in Linux Operating System

As multi-user operating system, many users can log in to the operating system at the same time. But not only limited to that aspect, even a user can switch to other user after that user successfully logged in to the operating system.

How can you even switch to another user after you successfully logged in to the Linux operating system ?. You can use the following command to do that :

username@hostname:~ $ su

It can be recognized which is the short abbreviation of switch user, substitute user or super user. It is actually depends on the purpose of the command’s execution.  We can describe several functions of the command as follows :

  1. Switch or substitute to another user.

We can switch to another user by using this command. Below is the image of executing the command :

04-check-username
Login as user which is ‘james’ and then switching to another user which is ‘root’ in this case. After each steps, executing command ‘whoami’ to find the currently logging user.
05-check-username
Logging in as ‘root’ and then switching to another user which is ‘james’ in this case. After each steps, executing command ‘whoami’ to find the currently logging user.

We are logging in with ‘root’ as the username. And following that, we are switching or substitution our user to another user. In the above case, we are switching to ‘james’.

  1. Gaining super user access.

We are gaining access as super user by switch ourselves to root. It can be also done by executing the command ‘su’. The following image shown it :

04-check-username

Another thing that is actually important following the command as an additional parameter is the dash or hyphen sign (-). The function of this additional parameter is described as follows :

  1. Changing the working directory to default directory of the user whom we are switching to. So, if switch ourselves to ‘root’, we will be automatically directed to /root/ as the current working active directory.
  2. The other thing is acquiring a new environment condition of the user whom we are switching to including all of the environment variables which is defined for the user whom we succeeded on logging into.

 

2 thoughts on “Switching User in Linux Operating System

Leave a Reply