
If Linux means something, means choice. You can accomplish even a simple task like identifying the current user in many ways.. This tutorial will show you how to use some of the quickest and easiest methods.
Why would you need to find the identity of the current user? In several cases the owner of the computer is the sole user and, without becoming too existential, they probably know themselves. Maybe, but it is also common for people to create additional user accounts to allow family members to have access to the computer. AND, if it is connected to a remote shell on a server somewhere, you may need a quick reminder of the username you logged in with. If you see a logged in session with no one present, How do you identify current user from command line?
Let's try the simplest option first. All we will do is look at the command prompt. By default, Linux distributions have the username at the prompt. Simple. We didn't even have to write anything.
If the user has changed their message to another format, we must try something else. the who
The command will give us the information we are looking for.
who
The output of who
gives you the name of the current user, the terminal to which it is connected, the date and time you logged in. If it is a remote session, it also tells us where it is connected from.
Compared, the whoami
The command provides a very concise answer:
whoami
You can get the same answer from a word by repeating the $USER
environment variable to screen.
echo $USER
The one-letter command w
requires less writing and provides more information.
w
the w
The command gives us the username, what we wanted, and an additional set of data for that user. Note that if there are multiple users connected to the Linux system, the w
The command will list them all. You would need to know in which terminal the user you were interested in had logged in to. If they are directly logged into the Linux computer, will be pts / O, therefore look for: 0 at the exit of w
.
the w
The command provides the boot time, the average uptime and load for the last five, ten and fifteen minutes, and the next information about the current user.
- USERNAME: The username.
- TTY: The type of terminal they are connected to. In general, it will be a pts (a pseudo-teletype). : 0 means the physical keyboard and screen connected to this computer.
- FROM: The name of the remote host if it is a remote connection.
- ACCESS@: The time the user logged in.
- INACTIVE: Inactivity time. This shows? Xdm? in the screenshot because we are running an X-windows Display Manager, that does not provide that information.
- JCPU: Set CPU time, this is the CPU time used by all the processes that have been attached to this tty. In other words, the total CPU time of this user in this logged in session.
- PCPU: Procedure CPU time, this is the CPU time used by the current procedure. The current procedure is named in the WHAT column.
- THAT: The command line of this user's current procedure.
Now that we know who this user is, we can get more information about him. the id
The command is a good place to start. Writes id
, a space, the username and hit enter.
id dave
This gives us your user ID (uid), Group id (guide) and the groups he is a member of. A less cluttered display of groups can be obtained by using the groups
command.
groups dave
A good summary is provided by the finger
command. Use apt-get
to install this package on your system if you are using Ubuntu or other Debian based distribution. On other Linux distributions, use the package management tool of your Linux distribution.
sudo apt-get install finger
Once you have finger
installed, you can use it to display information about the user in question.
dedo dave
On most Linux systems, some of these fields will be blank. The office, full name and phone numbers are not filled in by default. Field “no plan” no plan, what you were working on or planning to do. If you edit the .plan file in your home folder, the content of that file is attached to the output of finger
.
To quickly reveal the name of the user who logged in from the GNOME desktop used in Ubuntu and many other Linux distributions, click on the system menu in the upper right corner of your screen. The bottom entry of the dropdown menu is the username. Other Linux desktop environments should display your username in an equally easy-to-find menu.
That was easy, just one click. But, Where's the fun in that?
You don't feel like a digital detective in the same way as when you wear the Bash shell.