Introduction to users in Linux

Users are important factors in Linux. In this article, we will discuss about how to identify a system’s user account with commands like who, whoami, etc.

Linux environment can allow multiple users to work in same system. Each user will have their own account and permission to different aspects on the system. One user can also get information about other user.

We will also discuss on, how to log in into a second user account and run program with the help of su and sudo command.

whoami command

The whoami command are tell about the system’s username.

Sample syntax of whoami :

$ whoami

who command

The who command gives the information about the users logged in to the system.

Sample syntax of who command :

$ who  

Example Output

sufian    :0    2020-09-02 13:54 (:0)

w command

The w command tells about who is logged in and what are they doing.

Sample syntax of w command :

$  w  

id command

id command tells about your user id, primary group id, and a list of groups that belongs to you.

Sample syntax of id command :

$ id      

Linux su Commands

su command allows you to login to another user.

Sample syntax of su command :

$ su <username>  

Like example of su command :

$ su test

See your terminal after run the command, user account is changed from student to test.

Logging in to root user

Simply su or su root is used to logging in to the root user.

Sample syntax of su root command:

$ su root  

Please note that, in this way, you need to enter the root users password.

Logging in to any user with root user

The root user can become any existing user without knowing that user’s password.

Example of su as root command :

# su - student  

When we run this command as root user, we directly login to the student user (as example here). We don’t need to enter the user’s password here.

Enter exit, to logout in the terminal.

Command With sudo

Command sudo are allowed to create new users on the system without becoming root or without knowing the root password.

Example of sudo :

$ sudo apt update

The apt update command can be executed as the root user, or the user who has super user previledges.

sudo su –

Some Linux systems like Ubuntu, don’t have a password set for root user by default. That means you can’t login as root user.

Perform root like task, a user is given all sudo rights via etc/sudoers. Every users that are members of the admin group can use sudo command for performing root tasks.

Sample syntax of sudo su – :

# grep admin /etc/sudoers  

See your terminal after run the command, command “grep admin /etc/sudoers” allows all the admin group users to gain root privileges.

sudo su – a user can become root user without typing password for root. Linux sudo command will ask for the user’s own password.

Sample syntax of :

# sudo su –

See your terminal after run the command, bash is asking for student password not for root password, after that we are logged in as root user.

Leave a Reply