Friday, 2 May 2014

Basic - User Information & Activities on Server.

finger

The finger command displays information about the system users. We can view all information about user if we know the user account login name.

- To view details about a particular user.

# finger subrat
Login: subrat                         Name: Subrat Nayak
Directory: /home/subrat               Shell: /bin/bash
On since Mon Apr  1 18:45 (IST) on :0 (messages off)
On since Mon Apr  1 18:46 (IST) on pts/0 from :0.0
New mail received Fri May  1 10:33 2014 (IST)
Unread since Sat Apr  19 12:59 2014 (IST)
No Plan.


- To view login details & idle status about an user.
# finger -s root
Login     Name  Tty   Idle  Login Time   Office     Office Phone
root      root  *1    2d    Mon 13:45
root      root  *2    1d    Wed 19:53
root      root  *3          Thu 08:20
root      root  *ta   2     Fri 21:43
root      root  *tb   2     Sat 05:44


who

The who command shows currently who is logged on to the system. This is a useful command because it can check how many users currently logged in the system, who they are & what they are doing.

[root@subrat ~]# who
root    pts/0        2014-05-02 06:22 (subrat.com)
subrat  pts/1        2014-05-02 07:29 (subrat.com)
dinesh  pts/2        2014-04-30 19:17 (subrat.com)


- To view the date & time of last system boot.
[root@subrat ~]# who -b
         system boot  2014-04-19 15:12

- To view the system's current runlevel.
[root@subrat ~]# who -r
         run-level 3  2014-04-19 15:12


- To lists users logged in. After the login time, the who command prints the number of hours & minutes that the user has been idle.
[root@subrat ~]# who -u
root    pts/0     2014-05-02 06:22    .       17634 (subrat.com)
subrat  pts/1     2014-05-02 07:29  00:11     18109 (subrat.com)
dinesh  pts/2     2014-04-30 19:17   old      13276 (subrat.com)

Note: . means the user was active in the last minute.
         old means the user has been idle for more than 24 hours.


- To view all login names & the number of users logged on.
[root@subrat ~]# who -q
root subrat dinesh
# users=3

- To view only hostname & user associated with stdin. It the same as running who am i command.
[root@subrat ~]# who -m
root    pts/0        2014-05-02 06:22 (subrat.com)


- To list only the entries that correspond to processes via which the system is waiting for a user to login. The user name is always LOGIN.
[root@subrat ~]# who -l
LOGIN    tty2         2014-04-19 15:12              1214 id=2
LOGIN    tty1         2014-04-19 15:12              1212 id=1
LOGIN    tty3         2014-04-19 15:12              1216 id=3
LOGIN    tty4         2014-04-19 15:12              1218 id=4
LOGIN    tty5         2014-04-19 15:12              1222 id=5
LOGIN    tty6         2014-04-19 15:12              1224 id=6


w

The w command shows who is logged on in Linux system and what they are doing. Its function is identical to the who command but the w command output provides more detail than who command. Somehow, the first line is the output of uptime command which has explained in other post.

[root@subrat ~]# w
07:30:21 up 12 days, 16:18, 2 users, load average: 0.03, 0.00, 0.00
USER     TTY      FROM    LOGIN@  IDLE   JCPU   PCPU  WHAT

root     pts/0    subrat  06:22   0.00s  0.26s  0.23s sshd: root
subrat   pts/1    subrat  07:29   28.00s 0.02s  0.02s -bash
 

[root@subrat ~]# w -l
07:45:54 up 12 days, 16:34,  2 users, load average: 0.03, 0.00, 0.00
USER     TTY     FROM  LOGIN@   IDLE   JCPU   PCPU WHAT

root    pts/0   subrat 06:22   0.00s  0.27s  0.23s sshd: root
subrat  pts/1   subrat 07:29   16:01  0.02s  0.02s -bash
 

- To view login details without header.
[root@subrat ~]# w -h
root   pts/0  subrat 06:22   0.00s  0.27s  0.23s sshd: root

subrat pts/1  subrat 07:29   16:30  0.02s  0.02s -bash

whoami

The whoami command displays the user name (i.e., login name) of the owner of the current login session. After switch to other user, it will show the switched user's login name.

 root@subrat ~]# whoami
root

[root@subrat ~]# su - dinesh
[dinesh@subrat ~]$ whoami
dinesh


who am i

The who am i command allows you to display the login name, terminal name, & time of the login for that terminal. It is terminal dependent. After switch to user, unlike whoami, it will display the logged in user's information only, not about the switched user's information.

[root@subrat ~]# whoami
root
[root@subrat ~]# who am i
root    pts/0        2014-05-02 06:22 (subrat.com)
[root@subrat ~]# su - dinesh
[dinesh@subrat ~]$ whoami
dinesh
[dinesh@subrat ~]$ who am i
root    pts/0        2014-05-02 06:22 (subrat.com)
 

logname

The logname command displays the login name of the user who has loged in to that terminal. It is terminal dependent. After switch user, it won't display the switched user login name rather than the logged in user's name.

[root@subrat ~]# logname
root
[root@subrat ~]# su - dinesh
[dinesh@subrat]$ logname
root


users

The users command is used to display the user names of users currently logged in to the current host.
[root@subrat ~]# users
dinesh root subrat


id

The id command is used to display the system identifications of a specified user. We can find the information like user's UID, user's GID, all the secondary groups an user belongs to.

- To display the currently logged in user's UID, GID & other secondary groups associated with the user.

[root@subrat ~]# id
uid=0(root) gid=0(root) groups=0(root),2(daemon),3(sys),4(tty),5(operator),8(procview),12(everyone)


- To display the UID of currently logged in user.
[root@subrat ~]# id -u
0


- To display the GID of currenlty logged in user.
[root@subrat ~]# id -g
0


- To display all the secondary groups, the currenlty logged in user associated with.
[root@subrat ~]# id -G
2 3 4 5 8 12

- To display all the secondary groups names instead of ID, the currenlty logged in user associated with.
[root@subrat ~]# id -nG
daemon sys tty operator procview everyone


- To display the UID, GID & other groups associated of a particular user.
[root@subrat ~]# id subrat
uid=512(subrat) gid=512(subrat) groups=512(subrat),523(unix),531(sysadmin)


- To display the UID of a particular user.
[root@subrat ~]# id -u subrat
512

- To display the username instead of UID of a particular user.
[root@subrat ~]# id -nu subrat
subrat

- To display the GID of a particular user.
[root@subrat ~]# id -g subrat
512

- To display the GID of a particular user.

[root@subrat ~]# id -ng subrat
subrat


- To display all the secondary groups ID, an user associated with.
[root@subrat ~]# id -G subrat
523 531

- To display all the secondary groups name instead of ID, an user associated with.
[root@subrat ~]# id -nG subrat
unix sysadmin


groups

The groups command displays the groups a user is in.

- To display the currently logged in user's groups.
[root@subrat ~]# groups
root : root daemon sys tty operator procview everyone


- To display the groups of a particular user.
[root@subrat ~]# groups subrat
subrat : subrat unix sysadmin


members

The members command is used to list the usernames of the users belongs to a particular group.

[root@subrat ~]# members sysadmin
subrat kiran alert operator portaladmin

lid

The lid command is used to list the usernames and user ids of the users belongs to a particular group.

[root@subrat ~]# lid -g sysadmin
subrat(uid=512)
kiran(uid=534)
alert(uid=567)
operator(uid=900)

portaladmin(uid=902)

last

The last command is used to listing the last times a user logged in on server. It keeps the information from the first boot of the server.
[root@subrat.com ~]# last | less
[root@subrat.com ~]# last
subrat   pts/1        subrat.com       Fri May  2 07:29   still logged in
root     pts/0        subrat.com       Fri May  2 06:22   still logged in
...
...
dinesh   pts/0        subrat.com       Thu Apr 24 10:10 - 11:39  (01:28)
subrat   pts/1        subrat.com       Wed Apr 23 09:27 - 12:05  (02:37)
root     pts/0        subrat.com       Sat Apr 19 15:13 - 15:42  (00:28)
reboot   system boot  2.6.32-431.el6.x Sat Apr 19 15:12 - 11:00 (12+19:48)
...
...
reboot   system boot  2.6.32-358.el6.x Sun Dec 22 17:38 - 12:00  (18:21)


- To display the login details of a particular user.
[root@subrat.com ~]# last subrat
subrat   pts/1      subrat.com  Fri May  2 07:29   still logged in
subrat   pts/1      subrat.com  Mon Apr 14 11:01 - 13:07  (02:05)
subrat   pts/2      subrat.com  Wed Apr  9 14:20 - 14:42  (00:21)
subrat   pts/1      subrat.com  Wed Apr  9 13:54 - 14:22  (00:28)
subrat   pts/0      subrat.com  Wed Apr  9 13:33 - 13:39  (00:06)
...
...


- To hide the hostname field.
[root@subrat ~]# last -R subrat
subrat   pts/1        Fri May  2 07:29   still logged in
subrat   pts/1        Mon Apr 14 11:01 - 13:07  (02:05)
subrat   pts/2        Wed Apr  9 14:20 - 14:42  (00:21)
subrat   pts/1        Wed Apr  9 13:54 - 14:22  (00:28)
...
...


- To display the complete login & logout times.
[root@subrat ~]# last -F
subrat   pts/1    subrat.com Fri May  2 07:29:53 2014   still logged in
root     pts/0    subrat.com Fri May  2 06:22:59 2014   still logged in
dinesh   pts/0    subrat.com Mon Apr 28 12:46:20 2014 - Mon Apr 28 12:54:23 2014  (00:08)
subrat   pts/0    subrat.com Mon Apr 28 08:50:53 2014 - Mon Apr 28 10:45:33 2014  (01:54)
...
...


- To find users last logged in/out time from a specified time to back.
Use: last -t YYYYMMDDHHMMSS

[root@subrat ~]# last -t 20140314110100
dinesh   pts/2        subrat.com  Fri Mar  7 10:02 - 11:20  (01:17)
subrat   pts/1        subrat.com  Fri Mar  7 09:36 - 11:45  (02:08)
...
...
root     pts/0        subrat.com  Sun Dec 22 17:41 - 18:35  (00:54)
reboot   system boot  2.6.32-358. Sun Dec 22 17:38 - 12:00  (18:21)


- To display last shutdown time.
[root@subrat.com ~]# last -x shutdown
shutdown system down  2.6.32-431.1.2.e Sat Apr 19 15:12 - 15:12  (00:00)
shutdown system down  2.6.32-431.1.2.e Thu Feb 13 12:00 - 12:01  (00:01)

...
...
shutdown system down  2.6.32-358.el6.x Mon Dec 23 21:09 - 12:00 (51+14:51)


No comments:

Post a Comment