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
- 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
May be interested
- How to manage Linux services using Systemdone of the most important skills that any new systemd user needs to learn is how to manage computer services. this article will teach you the basics: start, stop, enable and disable services from the linux command line.
- How to set and change a user password in Linuxboth linux and unix operating systems use the passwd command to change the user password. the password used to update the user's authentication token (password) is stored in the / etc / shadow file.
- How to check all services running in Linuxneed to know all the services running on the system. in this article, tipsmake.com will show you all possible ways to list the services running on linux computers.
- How to check the time of shutdown and reboot in Linuxthere are many reasons why you might want to find out when your linux computer is off, reboot or how long it will run. in most cases, this information is invaluable in debugging a problem.
- How to check the desktop environment you are using on Linuxas you probably know, linux-based operating systems are heavily focused on the command line to perform operations. a minimal distro like arch linux will give you a dark terminal installation.
- How to check the pressure of a Linux systemtesting pressure on linux servers is a good idea if you want to see if they work well. in this post, tipsmake introduces some tools that can help you add pressure to the system to test and evaluate results.
- How to check and manage disk space in Linuxa common problem is that updates fail due to a lack of disk space, but there are some simple tests that users can perform when they encounter an error message, to keep critical systems smooth operation.
- How to Check IP Address on Linuxthis article shows you how to view the private and public ip addresses of computers using the linux operating system.
- Basic Linux commands everyone needs to knowwhen using linux, you should also learn basic linux commands to make operations quicker and easier. here are some basic commands on linux you should know.
- 8 methods to quickly check website status from Linux Terminalthis tutorial will show you how to quickly check if a particular website is working from the linux terminal.