1 查询目前已登录的用户信息w 或者 who
代码语言:javascript复制[@bjzw_11_210 ~]# w
14:03:18 up 342 days, 16:01, 2 users, load average: 0.03, 0.04, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 10.149.239.20 Thu13 0.00s 0.19s 0.00s w
guest pts/2 10.139.239.20 Thu15 22:43m 0.02s 0.02s -bash
第一行显示当前时间,开机(up)多久,几个用户在系统上的平均负载等; 第二行是各个项目(列名)的说明; 第三行以后,每行代表一个用户。如上,root登录,并取得终端机名pts/0,pts/1等。
代码语言:javascript复制[@tc_62_179 blog_spider]# who
root pts/0 2017-12-05 09:50 (10.149.239.20)
root pts/1 2017-12-07 20:41 (10.149.239.20)
2 查询每个账号最近登录时间lastlog
代码语言:javascript复制[@tc_62_179 blog_spider]# lastlog
Username Port From Latest
root pts/1 10.149.239.20 Thu Dec 7 20:41:32 0800 2017
bin **Never logged in**
daemon **Never logged in**
adm **Never logged in**
lp **Never logged in**
sync **Never logged in**
shutdown **Never logged in**
halt **Never logged in**
mail **Never logged in**
operator **Never logged in**
games **Never logged in**
ftp **Never logged in**
nobody **Never logged in**
avahi-autoipd **Never logged in**
systemd-bus-proxy **Never logged in**
systemd-network **Never logged in**
dbus **Never logged in**
polkitd **Never logged in**
abrt **Never logged in**
libstoragemgmt **Never logged in**
rpc **Never logged in**
postfix **Never logged in**
pcp **Never logged in**
tss **Never logged in**
unbound **Never logged in**
ntp **Never logged in**
rpcuser **Never logged in**
nfsnobody **Never logged in**
sssd **Never logged in**
chrony **Never logged in**
sshd **Never logged in**
tcpdump **Never logged in**
oprofile **Never logged in**
odin pts/0 10.142.239.25 Sun Nov 12 19:50:11 0800 2017
apache **Never logged in**
netmonitor **Never logged in**
guest **Never logged in**
nscd **Never logged in**
本质是查看/var/log/lastlog
3 查看指定用户的属主属组等信息id
代码语言:javascript复制[@tc_62_179 blog_spider]# id
uid=0(root) gid=0(root) groups=0(root)
[@tc_62_179 blog_spider]# id odin
uid=1000(odin) gid=1000(odin) groups=1000(odin),6(disk)