Often you may need to find out user information in Linux. There are several commands to do this easily in Linux. In this article, we will learn how to check user login details in Linux.
How to Check User Login Details in Linux
Here are the different commands to get user details in Linux.
1. id command
id shows a real and effective user and group IDs. Here is an example.
$ id ubuntu uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),130(sambashare)
2. groups command
groups command shows all the different groups a user belongs to. Here is an example to view all the groups for user ubuntu.
$ groups ubuntu ubuntu : ubuntu adm cdrom sudo dip plugdev lpadmin sambashare
3. finger command
You can also use finger command to search for user information on Linux systems. Here is the command to install finger command.
$ sudo apt install finger #Debian/Ubuntu $ sudo yum install finger #RHEL/CentOS $ sudo dnf install finger #Fedora 22+
The finger command shows a user’s real name, home directory, shell, login name, time and so on. Here is an example.
$ finger ubuntu Login: ubuntu Name: Ubuntu Directory: /home/ubuntu Shell: /bin/bash On since Fri Sep 22 10:39 (IST) on tty8 from :0 2 hours 1 minute idle No mail. No Plan.
4. grep command
One of the simplest ways to search for user details is to use grep command. You can easily use grep command to search for a specific user’s information in /etc/passwd file which stores login details of all users.
$ grep -i ubuntu /etc/passwd ubuntu:x:1000:1000:Ubuntu,,,:/home/ubuntu:/bin/bash
5. Logged in Users
There are several commands to get list of logged in users. users command will list all users who are logged in your system.
$ users ubuntu test_user
who command will display all users who are logged in, and the terminal from where they are logged in.
$ who -u ubuntu tty8 2017-09-22 10:39 02:09 2067 (:0)
Alternatively, you can also use ‘w’ command to list all users that are currently logged into your system.
$ w 12:46:54 up 2:10, 1 user, load average: 0.34, 0.44, 0.57 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT ubuntu tty8 :0 10:39 2:10m 4:43 0.46s cinnamon-sessio
In this article, we have learnt several simple commands to find user details in Linux. These work on almost all Linux systems.
Also read:
How to Force CP Command to Overwrite
How to Force Delete Directory in Linux
How to Upload File Asynchronously in JS
How to Store Data in Local Storage in JavaScript
How to Display Local Storage Data in JavaScript