4 Ways to Identify the logged-in on Your Linux System
As a system administrator, you can often (at some point) need to see which users in your system are active. Sometimes you even need to know what they are doing. This article summarizes 4 ways to view system user information (by number (ID)).
1. Use the W command to view the process information that the logged on user is using
The W command is used to display the names of the users who have logged in to the system and what they are doing. The information used by this command originates from the/var/run/utmp file. The information for the W command output includes:
- User name
- User's machine name or TTY number
- Remote Host Address
- Time the user logged on to the system
- Idle time (little effect)
- The time taken to attach to the TTY (terminal) process (jcpu time)
- Time spent by current process (pcpu time)
- Commands that the user is currently using
The W command can also use the following options
- -H Ignores header file information
- -U Displays the load time of the result
- -S does not show JCPU, PCPU, logon Hours
$W23:04:27 up (7:51), 3 users, load average:0.04, 0.06, 0.02USER TTY from [email protected] IDLE jcpu PCPU whatramesh pts/0 dev-db-server 22:57 8.00s 0.05s 0.01s Sshd:ramesh [Priv]jason PTS/1 dev-db-server 23:01 2:53 0.01s 0.01s-bashjohn pts/2 dev-db-server 23:04 0.00s 0.0 0s 0.00s w$w-hRamesh pts/0 dev-db-server 22:57 17:43 2.52s 0.01s sshd:ramesh [Priv]jason pts/1 Dev-db-server 23:01 20:28 0.01s 0.01s-bashjohn pts/2 dev-db-server 23:04 0.00s 0.03s 0.00s w-h$W-u23:22:06 up (8:08), 3 users, Load average:0.00, 0.00, 0.00USER TTY from [email protected] IDLE jcpu PCPU whatramesh pts/0 dev-db-server 22:57 17:47 2.52s 2.49s topjason pts/1 dev-db- Server 23:01 20:32 0.01s 0.01s-bashjohn pts/2 dev-db-server 23:04 0.00s 0.03s 0.00s w-u$w-s23:22:10 up (8:08), 3 users, Load average:0.00, 0.00, 0.00USER TTY from IDLE Whatramesh pts/0 dev-db-server 17:51 Sshd:ramesh [Priv]jason pts/1 dev-db-server 20:36-bashjohn pts/ 2 Dev-db-server 1.00s W-s
2. Use the WHO command to view (log in) the user name and the process that was started
The WHO command is used to enumerate the user names of the currently logged on system. The output is: User name, TTY number, time date, host address.
who ramesh pts/0 2009-03-28 22:57 (dev-db-server) Jason pts/1 2009-03-28 23:01 (dev-db-server) John Pts/2 2009-03-28 23:04 (dev-db-server)
If you only want to list users, you can use the following statement:
Who | cut-d '-f1 | sort | uniqJohnjasonramesh
Supplemental : The Users command, which can be used to print out the user name of the logon server. This command has no options other than the Help and version options. If a user uses more than one terminal, multiple duplicate user names are displayed accordingly.
usersJohn Jason Ramesh
3. Use the WhoAmI command to see the login name you are using
The WhoAmI command is used to display the logged-in user name.
WhoAmIJohn
The WhoAmI command performs exactly the same as the Id-un effect, for example:
Id-unJohn
The WhoAmI command displays the name of the user currently logged in and the TTY information currently being used. The output of this command includes the following: User name, TTY name, current time date, and also the link address used by the user to log on to the system.
Who am IJohn pts/2 who mom likesJohn Pts/2 2009-03-28 23:04 (dev-db-server) Warning: Don ' t try "whoMom hates" command.
Of course, if you use the SU command to change the user, the results displayed by the command (WHOAMI) will change.
4. Always view the system's historical information (user information that was used by the system)
The last command can be used to display the history of a particular user's login system. If no parameters are specified, the history information for all users is displayed. By default, this information (the information displayed) is derived from the/var/log/wtmp file. The output of this command contains the following columns of information:
- User name
- TTY Device number
- History Login Time Date
- Log out time and date
- Total working hours
Last JasonJason pts/0 dev-db-server Fri Mar 22:57 still logged Injason pts/0 Dev-db-server Fri Mar 22:09-22:54 (00:45) Jason pts/0 dev-db-server Wed Mar 25 19:58-22:26< c12/> (02:28) Jason pts/1 dev-db-server Mon Mar 20:10-21:44 (01:33) Jason pts/0 192.168.201.11 Fri Mar 08:35-16:46 (08:11) Jason pts/1 192.168.201.12 Thu Mar 12 09:03-09 : (00:15) Jason pts/0 dev-db-server Wed Mar 20:11-20:50 (00:39
The author of this paper is Hari Haran. He works for BK Systems (p) LTD and is committed to working with open source software.
Citation: http://blog.csdn.net/newdriver2783/article/details/8059368
4 ways to view your system's current logged-on user information under Linux