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.
How to check the current user on Linux
- Check the current user from the command line
- Use the who, whoami and environment variables $ USER
- Use w command
- Use the id command for more information about users
- 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.
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
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
You can get the same answer by repeating the $ USER environment variable .
echo $USER
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.
- USER: User name.
- 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.
- FROM: The name of the remote server if this is a remote connection.
- LOGIN @: Time that users log in.
- 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.
- 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.
- PCPU: Short for Process CPU . This is the CPU time used by the current process. The current process is named in the WHAT column .
- 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
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
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
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.
Is it easy to check the current user in Linux? Hope you are succesful.
You should read it
- 8 best Linux distros for pentest
- 5 ways to improve Linux user account security
- How Linux stores and manages user passwords
- How to access user activity on Linux
- How to set and change a user password in Linux
- 6 emulator websites to help use Linux online
- How to check the status of using laptop battery running Linux
- 10 reasons you can't not 'love' Linux Mint
- Signal and Trap in Unix / Linux
- How to Manage Users in Linux
- How to manage Linux services using Systemd
- Linux distro for new, easy to use, beautiful
Maybe you are interested
Many Samsung users found using 'samsung' as password
YouTube Will Let Third Parties Train AI Models on User Content
US users can now access ChatGPT via 1-800-CHATGPT
How to Change the Default User Account Avatar in Windows
2 features users don't like in Photoshop Express photo editing application
Microsoft still recommends 15-year-old backup solution for Windows 11 and 10 users