linux查看用户登录信息
linux是一个多用户系统,一般用户都是通过ssh工具远程登录linux,同一时间可能有不只一个用户在登录使用linux.
可以通过who命令查看在线用户信息。
用w和who命令列出当前系统所有已经登录的用户信息:
第二行是各个字段的名称,
从第三行开始每行代表一个用户。例如上面peter用户的登录终端为tty7,登录时间为09:51。
who命令和w命令类似,也是显示系统中所有在线用户的信息,只是信息量相对w要简洁一些:
可以通过who命令查看在线用户信息。
1.w和who命令
回到顶部root@initroot:~$ w 14:37:06 up 4:46, 2 users, load average: 1.25, 0.61, 0.45 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 117.136.19.99 14:43 1.00s 0.00s 0.00s w peter tty7 :0 09:51 4:46m 4:22 1.02s cinnamon-session --session cinnamon第一行显示当前主机的一些基本信息,包括当前系统的时间,开机运行的时间,在线用户数以及系统的负载;
第二行是各个字段的名称,
从第三行开始每行代表一个用户。例如上面peter用户的登录终端为tty7,登录时间为09:51。
who命令和w命令类似,也是显示系统中所有在线用户的信息,只是信息量相对w要简洁一些:
root@initroot:~$ who root pts/0 2020-01-02 14:43 (117.136.19.99) peter tty7 2020-01-02 09:51 (:0)
Usage: who [OPTION]... [ FILE | ARG1 ARG2 ]
Print information about users who are currently logged in.
-a, --all same as -b -d --login -p -r -t -T -u
-b, --boot time of last system boot
-d, --dead print dead processes
-H, --heading print line of column headings
--ips print ips instead of hostnames. with --lookup,
canonicalizes based on stored IP, if available,
rather than stored hostname
-l, --login print system login processes
--lookup attempt to canonicalize hostnames via DNS
-m only hostname and user associated with stdin
-p, --process print active processes spawned by init
-q, --count all login names and number of users logged on
-r, --runlevel print current runlevel
-s, --short print only name, line, and time (default)
-t, --time print last system clock change
-T, -w, --mesg add user's message status as +, - or ?
-u, --users list users logged in
--message same as -T
--writable same as -T
--help display this help and exit
--version output version information and exit
If FILE is not specified, use /var/run/utmp. /var/log/wtmp as FILE is common.
If ARG1 ARG2 given, -m presumed: 'am i' or 'mom likes' are usual.
GNU coreutils online help: http://www.gnu.org/software/coreutils/ Full documentation at:
http://www.gnu.org/software/coreutils/who or available locally via: info '(coreutils) who invocation'
2.whoami命令
回到顶部who命令打印当前所有登录用户的信息,而whoami命令可以查看当前终端登录的用户名,简单点说就是打印自己的用户名:
peter@initroot:~$ whoami peter
Usage: whoami [OPTION]...
Print the user name associated with the current effective user ID.
Same as id -un.
--help display this help and exit
--version output version information and exit
GNU coreutils online help: http://www.gnu.org/software/coreutils/ Full documentation at:
http://www.gnu.org/software/coreutils/whoami or available locally via:
info '(coreutils) whoami invocation'
initroot编辑整理,转载请注明www.initroot.com
100次点赞
100次阅读