Check the current user on Linux

In Linux, you can perform simple tasks such as checking the current user in many ways. This tutorial will show you how to use some of the quickest and easiest ways to check users on Linux.

In Linux, you can perform simple tasks such as checking the current user in many ways. This tutorial will show you how to use some of the quickest and easiest ways to check users on Linux.

How to check the current user on Linux

  1. Check the current user from the command line
  2. Use the who, whoami and environment variables $ USER
  3. Use w command
  4. Use the id command for more information about users
  5. Use finger command

Check the current user from the command line

Why do you need to check the current user? In many cases, the owner of the computer is the only user and of course does not need to check again. But in reality, people often create additional user accounts to allow other family members to have access to computers. If you have connected to the remote shell on the server somewhere, you may need a quick prompt for the logged-in username. If you see a login session without anyone involved, how do you check the current user from the command line?

Try the easiest options first. All you need to do is look at the Command Prompt. By default, Linux distributions include usernames in the prompt. It's very simple and doesn't even need to enter anything.

Check the current user on Linux Picture 1Check the current user on Linux Picture 1

Use the who, whoami and environment variables $ USER

If the user has changed the prompt to another format, you need to try another method. The who command will provide the information we are looking for.

 who 

Check the current user on Linux Picture 2Check the current user on Linux Picture 2

The output of the who command gives you the name of the current user, the terminal they are logged in, the date and time of the login. If it is a remote session, the who command also indicates where the user logged in.

In addition, whoami command also gives a very concise answer:

 whoami 

Check the current user on Linux Picture 3Check the current user on Linux Picture 3

You can get the same answer by repeating the $ USER environment variable .

 echo $USER 

Check the current user on Linux Picture 4Check the current user on Linux Picture 4

Use w command

The command consists of a brief w letter but provides more information.

 w 

The w command provides the information you want (user name) and an additional set of data about that user. Note that if multiple users log on to the Linux system, the w command will list all those users. You need to know which user you are interested in logging in to any terminal. If they have logged in directly to the Linux computer, the result will be pts / o, so look for : 0 in the output of the w command.

The w command provides an average startup time, uptime and load time for the previous 5, 10 and 15 minute periods, as well as information related to the current user.

  1. USER: User name.
  2. TTY: The type of terminal they are logged in, usually a pts ( a pseudo-teletype ). : 0 means that the keyboard and physical screen are connected to this computer.
  3. FROM: The name of the remote server if this is a remote connection.
  4. LOGIN @: Time that users log in.
  5. IDLE: Time does not work. The screenshot above shows ? Xdm? Because the example has run under Display Manager of the Windows X system and does not provide this information.
  6. JCPU: Short for Joint CPU . This is the time the CPU is used by all processes attached to this terminal. In other words, the total time this user uses the CPU during this login session.
  7. PCPU: Short for Process CPU . This is the CPU time used by the current process. The current process is named in the WHAT column .
  8. WHAT: This user's command line is the current process.

Use the id command for more information about users

Now you know who this user is and can get more information about them. The id command is a great starting point. Enter id, space, user name and press Enter.

 id dave 

Check the current user on Linux Picture 5Check the current user on Linux Picture 5

This command will provide user ID ( uid ), group ID group ( gid ) and the group to which they are members. Display results can be collapsed using the groups command .

 groups dave 

Check the current user on Linux Picture 6Check the current user on Linux Picture 6

Use finger command

The finger command will create a neat summary of information. Use apt-get to install this package on your system, if you use Ubuntu or another Debian-based distribution. On other Linux distributions, use the distro's package management tool instead.

 sudo apt-get install finger 

After installing finger, you can use this command to display some information about the user who is interested.

 finger dave 

Check the current user on Linux Picture 7Check the current user on Linux Picture 7

On most Linux systems, some of these fields will be empty. Office, full name and phone number are not filled in by default. The 'No Plan' field refers to an old program, where you can provide a few notes for any interested user, about what you are or plan to do. If you edit the .plan file in the Home folder , the contents of that file will be added to the output of the finger command .

To quickly reveal the username logged in from the Gnome desktop used on Ubuntu and many other Linux distributions, click the system menu in the upper right corner of the screen. The bottom item in the drop-down menu is the user name. Other Linux desktop environments will display the user name in a similarly easy-to-find menu.

Check the current user on Linux Picture 8Check the current user on Linux Picture 8

Is it easy to check the current user in Linux? Hope you are succesful.

4.7 ★ | 3 Vote