If Linux means anything, it means choice. You can even solve a simple task, such as identifying the current user in several ways. This tutorial will show you how to use some of the fastest and easiest methods.
Why do you need to determine the identity of the current user? In many cases, the owner of the computer is the only user, and without being too existent, they probably know each other. Perhaps, but it is also common for users to create additional user accounts to allow family members access to the computer. If you're connected to a remote shell on a server somewhere, you might need a quick reminder of the username you're logged in with. If you see a logged in session with anyone, how do you identify the current user from the command line?
Try the simplest option first. All we have to do is to look at the prompt. By default, Linux distributions have the user name in the command prompt. Easy. We did not even have to enter anything.
If the user has changed his command prompt to a different format, we must try something different. The command
who gives us the information we are looking for.
<img class = "alignnone size-full wp-image-410427" data-pagespeed-lazy-src = "https://www.howtogeek.com/wp-content/uploads/2019/04 /xIdentify-User-from-CLI-02.png.pagespeed.gp+jp+jw+pj+ws+js+rj+rp+rw+ri+cp+md.ic.zDsLBXRNQ9.png "alt =" who- Command "width =" 644 "height =" 81 "src =" /pagespeed_static / 1. JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "; ] gives you the name of the current user, the device to which it is logged on, the date and time of login. If it's a remote session, you'll also know where you're logged in from.
For comparison The command
whoami yields a very striking answer:
and get the same one-word answer by displaying the environment variable
$ USER on the screen.
echo $ USER
<img class = "alignnone size-full wp-image-410429" data-pagespeed-lazy-src = "https://www.howtogeek.com/wp-content/uploads/2019 /04/xIdentify-User-from-CLI-04.png.pagespeed.gp+jp+jw+pj+ws+js+rj+rp+rw+ri+cp+md.ic.dzfBURXWPx.png "alt =" Use echo to display the user environment variable "width =" 644 "height =" 88 "src =" /pagespeed_static "19659004] The one-letter command
w requires less typing and provides more information.
w gives us the desired user name and a bonus record for that user.When multiple users are logged on to the Linux system are all listed with the command
w You need to know which device the user you were interested in has logged in. If you logged in directly to the Linux computer itself, if this is pts / o, look for 0 in the output of
w provides the boot time, the uptime, and the average load for the previous ones five, ten, and fifteen minutes, and the following information about the current user:
- USER : The username.
- TTY : The terminal to which you are logged in. This is usually a dot (a Pseudo-teletype): 0 means d The physical keyboard and screen connected to this computer.
- FROM : The name of the remote host, if it is a remote connection.
- LOGIN @ : The time the user logged in to.
- IDLE : Idle time. This shows? Xdm? in the screenshot, since we run under an X-Windows Display Manager, which does not provide this information.
- JCPU : Common CPU time, this is the CPU time used by all tty related processes. In other words, this user's total CPU time 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.
After knowing who this user is, we can get more information. The command
id is a good starting point. Type
id a space and the name of the user and press Enter.
<img class = "alignnone size-full wp-image-410431" data-pagespeed-lazy-src = "https://www.howtogeek.com/wp-content/uploads/2019/ 04 / xIdentify-User-from-CLI-06.png.pagespeed.gp + jp + jw + pj + ws + js + rj + rp + rw + ri + cp + md.ic.WDQ8taIoUh.png "alt =" output of the ID command "width =" 644 "height =" 109 "src =" /pagespeed_static/1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed .lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); (uid), group id (gid), and the groups they are a member of. A less clear display of groups can be obtained with the command
groups .  groups dave
<img class = "alignnone size-full wp-image-410432" data-pagespeed-lazy-src = "https://www.howtogeek.com/wp-content/uploads/2019/04/ xIdentify-User-from-CLI-07.png.pagespeed.gp + jp + jw + pj + ws + js + rj + rp + rw + ri + cp + md.ic.RNUvIfGL7Y.png "alt =" Output the group command "width = "644" height = "92" src = "/pagespeed_static/1.JiBnMqyl6S.gif" onload = "pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = "; by the
finger command Use
apt-get to install this package on your system if you have Ubuntu or any other Debian-based Instead, use the package management tool of your Linux distribution on other Linux distributions.
sudo apt-get install finger
After you install
finger you can use it to provide some user information show question.
On most Linux systems, some of these fields are empty, not including the office, full name, and phone numbers ausgefüll The "no plan" field refers to an old scheme in which you can give a few comments to anyone interested in what you have been working on or what you are planning to do. If you edit the .plan file in your home folder, the contents of that file will be sent to the output of
to quickly display the name of the logged in user on the GNOME desktop you are using Ubuntu and many other Linux distributions click on the system menu in the upper right corner of your screen. The bottom entry in the drop-down menu is the username. Other Linux desktop environments should display your username in a similarly easy-to-find menu.
But where is the fun?
One does not feel the same way as a digital detective does when using the bash shell.