screen命令不仅可以确保用户在极端情况下也不丢失对系统的远程控制,保证了生产环境中远程工作的不间断性,而且它还具有会话共享、分屏切割、会话锁定等实用的功能。其中,会话共享功能是一件很酷的事情,当多个用户同时控制主机的时候,它可以把屏幕内容共享出来,也就是说每个用户都可以看到相同的内容。
screen的会话共享功能的流程拓扑如图9-13所示。
图9-13 会话共享功能的流程拓扑
要实现会话共享功能,首先使用ssh服务程序将终端A远程连接到服务器,并创建一个会话窗口。
[root@client A ~]# ssh 192.168.10.10 The authenticity of host '192.168.10.10 (192.168.10.10)' can't be established. ECDSA key fingerprint is 70:3b:5d:37:96:7b:2e:a5:28:0d:7e:dc:47:6a:fe:5c. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.10.10' (ECDSA) to the list of known hosts. root@192.168.10.10's password:此处输入root管理员密码 Last login: Wed May 4 07:56:29 2017 [root@client A ~]# screen -S linuxprobe [root@client A ~]# 然后,使用ssh服务程序将终端B远程连接到服务器,并执行获取远程会话的命令。接下来,两台主机就能看到相同的内容了。
[root@client B ~]# ssh 192.168.10.10 The authenticity of host '192.168.10.10 (192.168.10.10)' can't be established. ECDSA key fingerprint is 70:3b:5d:37:96:7b:2e:a5:28:0d:7e:dc:47:6a:fe:5c. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.10.10' (ECDSA) to the list of known hosts. root@192.168.10.10's password:此处输入root管理员密码 Last login: Wed Feb 22 04:55:38 2017 from 192.168.10.10 [root@client B ~]# screen -x [root@client B ~]