Quick Links

Key Takeaways

Linux distributions normally display the username of the current user in the Terminal as (Username)@ComputerName. If your Linux distribution doesn't, run "who" or "whoami" in the Terminal to get the username instead. You can use the "w" command to get even more detailed information.

If Linux means anything, it means choice. You can achieve 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 many cases the owner of the computer is the only user and, without getting too existential, they probably know themselves. Perhaps, but it is also common for people to create additional user accounts to allow family members to have access to the computer. And, if you're connected to a remote shell on a server somewhere, you may need a quick reminder of the username you're logged in with. If you see a logged in session with no one in attendance, how do you identify the current user from the command line?

Find Your Current User by Looking at the Terminal

Let's try the easiest option first. All we need to do is look at the command prompt. By default, Linux distributions have the username in the prompt. Simple. We didn't even have to type a thing. You can see the username — Dave, in this case — next to "@howtogeek". Generally this will be displayed YourName@YourPCName,

User name shown in command prompt

If the user has changed their prompt to some other format we need to try something else.

Use who to Get the Current User

The who command will give us the information we are looking for on any Linux distro.

who

Output from the who command

The output from who gives you the name of the current user, the terminal they are logged in at, the date and time when they logged in. If it is a remote session, it also tell us where they are logged in from.

Use whoamii to Find the Current User

The whoami command will also display the current user.

By comparison to the who, the whoami command provides a very pithy answer. It only displays the username and nothing else.

whoami

Output from the whoami command

You can get the same one-word answer by echoing the $USER environment variable to the screen.

echo $USER

Using echo to display the user environment variable

Use w to Find the Current User and Extra Information

The one-letter command w requires less typing and provides more information.

w

Output from the w command

The w command provides us with the user name which is what we wanted, and a bonus set of data for that user. Note that if there are multiple users logged into the Linux system, the w command will list them all. You'd need to know which terminal the user you were interested in had logged in on. If they've logged directly onto the Linux computer itself, that'll be pts/o, so look for :0 in the output from w .

The w command provides the boot time, uptime and average load for the previous five, ten and fifteen minutes, and the following information regarding the current user.

  • USER: The user name.
  • TTY: The type of terminal they are logged in at. This will usually 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 this is a remote connection.
  • LOGIN@: The time at which the user logged in.
  • IDLE: Idle time. This shows ?xdm? in the screenshot because we're running under an X-windows Display Manager, which does not provide that information.
  • JCPU: Joint CPU time, this is the CPU time used by all processes that have been attached to this tty. In other words, the total CPU time of this user in this logged in session.
  • PCPU: Process CPU time, this is the CPU time used by the current process. The current process is named in the WHAT column.
  • WHAT: The command line of this user's current process.

What Can You Do With a Username?

Now that we know who this user is, we can obtain more information about them. The id command is a good place to start. Type id, a space, the name of the user and press enter.

id dave

Output from the id command

This gives us their user ID (uid), group ID (gid) and the groups they're a member of. A less cluttered display of the groups can be obtained by using the groups command.

groups dave

Output from the groups command

A nice summary is provided by the finger command. Use apt-get to install this package onto your system if you're using Ubuntu or another Debian-based distribution. On other Linux distributions, use your Linux distribution's package management tool instead.

sudo apt-get install finger

Once you have finger installed, you can use it to display some information about the user in question.

finger dave

Output from the finger command

On most Linux systems, some of these fields will be blank. The office, full name, and phone numbers are not populated by default. The "No Plan" field refers to an old scheme where you could provide a few notes for whoever was interested, about what you were working on, or planning to do. If you edit the .plan file in your home folder, the contents of that file are appended to the output from finger .

In some distros you may find the name of the current user displayed in the System Menu in the upper right corner of your screen, but that varies depending on your desktop environment.

Linux Commands

Files

tar · pv · cat · tac · chmod · grep · diff · sed · ar · man · pushd · popd · fsck · testdisk · seq · fd · pandoc · cd · $PATH · awk · join · jq · fold · uniq · journalctl · tail · stat · ls · fstab · echo · less · chgrp · chown · rev · look · strings · type · rename · zip · unzip · mount · umount · install · fdisk · mkfs · rm · rmdir · rsync · df · gpg · vi · nano · mkdir · du · ln · patch · convert · rclone · shred · srm · scp · gzip · chattr · cut · find · umask · wc · tr

Processes

alias · screen · top · nice · renice · progress · strace · systemd · tmux · chsh · history · at · batch · free · which · dmesg · chfn · usermod · ps · chroot · xargs · tty · pinky · lsof · vmstat · timeout · wall · yes · kill · sleep · sudo · su · time · groupadd · usermod · groups · lshw · shutdown · reboot · halt · poweroff · passwd · lscpu · crontab · date · bg · fg · pidof · nohup · pmap

Networking

netstat · ping · traceroute · ip · ss · whois · fail2ban · bmon · dig · finger · nmap · ftp · curl · wget · who · whoami · w · iptables · ssh-keygen · ufw · arping · firewalld