linux中who命令显示的pts/0和(:0)(:0.0)是什么意思?

时间:2022-06-01 16:36:11

原回答链接:http://zhidao.baidu.com/link?url=kXSnkh-C6VFzGtEN82TmugepfzvWzDXGf12-YqoSN6SNgZeKxR7jY2DBZDIxVVXRkvd_Nfi_pzyLDx8FxNfJhK

先说pts/0吧,man里面是这样说的:ptmx and pts - pseudo-terminal master and slave,pts是所谓的伪终端或虚拟终端,具体表现就是你打开一个终端,这个终端就叫pts/0,如果你再打开一个终端,这个新的终端就叫pts /1。比如用who命令查询当前登录的用户,可以看到每个用户的TTY设备(简单来说就是用户输入命令还有显示信息的设备,比如终端),下面是我机器上的显示:
calabash tty7 2009-12-09 20:04 (:0)
calabash pts/0 2009-12-09 20:20 (:0.0)
calabash pts/1 2009-12-09 20:27 (:0.0)
有一个tty7是表示图形界面,我当前登录的是GNOME,当然就是图形界面了。还有tty1-tty6表示文字界面,可以用Ctrl+Alt+F1-F6切换,+F7就是切换回图形界面。下面两行说明我当前打开了两个终端窗口,所以就有pts/0和pts/1

再说一下SSH吧,要把本机当做一个远程SSH服务器用,要先装个openssh-server,装完之后会自动启动sshd服务监听ssh连接,Ubuntu应该是预装了openssh-client的,所以启动sshd后,可以自己连接自己,最简单的命令:ssh user@localhost 至于Windows下面可以用putty用作ssh连接客户端。然后突然想起很久以前小龚推荐我注册的一个unix- center的账号可以登录上面的主机,就是SSH连接的。今天在公司就一直挂在unix- center的Ubuntu上面,发现上面登录的用户还真不少:
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
k418675 pts/2 202.108.140.161 08:32 3:42 0.08s 0.06s sshd: k418675 [
wateran_ pts/3 222.92.112.66 08:41 8:06 0.06s 0.06s -bash
xiaoshe pts/4 129.192.196.5 14:17 11:17m 0.08s 0.08s -bash
lfly pts/5 211.144.118.166 09:33 0.00s 0.24s 0.06s sshd: lfly [pri
steed.de pts/6 119.145.41.2 11:58 4:49 0.06s 0.06s -bash
topojuly pts/7 218.30.165.69 15:46 10:55m 0.10s 0.10s -bash
nwpumabi pts/8 222.92.112.66 15:12 1:35 0.08s 0.08s -bash
ilylm pts/9 113.96.216.247 16:26 1:15m 0.08s 0.08s -bash
niugao pts/10 :1.0 09:10 7:36 0.06s 0.06s -bash
niugao pts/11 :2.0 09:11 7:36 0.08s 0.08s -bash
cu911 pts/12 221.215.10.154 16:38 0.00s 0.10s 0.02s vi ./newhead.sh
wendao4 pts/13 113.9.75.218 16:47 3.00s 0.08s 0.08s -bash
clyet pts/15 218.247.11.196 14:12 2:07 0.08s 0.02s sshd: clyet [pr
bigarmy pts/17 124.207.17.24 10:46 4:22m 0.10s 0.10s -bash
tonylu pts/16 218.18.214.166 14:19 2:13m 0.08s 0.08s -bash
nwpumabi pts/19 222.92.112.66 11:08 5:38 0.08s 0.08s -bash
vector09 pts/23 :8.0 11:18 5:26 0.38s 0.10s -bash
vector09 pts/24 :9.0 11:18 5:29 0.08s 0.08s -bash
vector09 pts/21 :8.0 11:23 5:24 0.08s 0.08s bash
fishruby pts/26 118.229.195.133 15:04 1:03 0.08s 0.08s -bash
jy016492 pts/28 218.17.152.141 15:17 7:56m 0.08s 0.00s sshd: jy0164921
xingzj01 pts/29 222.92.112.66 12:46 4:00 0.08s 0.08s -bash
ls87 pts/30 192.168.1.18 13:39 4:43m 0.20s 0.04s vim
可以看到有很多pts,就是代表每个用户用来输入输出的终端了