我希望能够通过桌面上的单个ssh命令在远程服务器上启动屏幕会话。 但是,屏幕似乎需要一个terminal,这通过ssh运行命令时不可用。
所以很明显
ssh [email protected] screen "tail -f /var/log/messages"
(作为例子)不起作用,并给予
Must be connected to a terminal.
我希望ssh在屏幕下启动命令,以便稍后login并按照我将手动启动的屏幕会话进行连接。
尝试使用-t选项来ssh
ssh -t [email protected] screen "tail -f /var/log/messages"
从男人ssh
-t强制伪tty分配。 这可以用来执行arbi- 在远程机器上传输基于屏幕的程序,可以 非常有用,例如,在实现菜单服务时。 多重-t 选项强制tty分配,即使ssh没有本地tty。
您可以使用:
ssh root@host screen -m -d "tail -f /var/log/messages"
这启动一个分离的屏幕上运行的命令。
-m causes screen to ignore the $STY environment variable. With "screen -m" creation of a new session is enforced, regardless whether screen is called from within another screen session or not. This flag has a special meaning in connection with the `-d' option: -d -m Start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.
迟到的答案,但是这就是我所做的,我做了一个别名(我们称之为):
ssh $MYSERVER -a -x -t screen -xRR -A -e^Zz -U -O
这告诉ssh
禁用代理和X11转发,并告诉screen
附加到正在运行的会话,如果需要启动一个新的,使用^Z
作为breakout命令,使用UTF-8并聪明的terminal。
这一切意味着我可以打开一个terminal,键入t
,它会打开我的$ MYSERVER屏幕会话。 然后,我可以打开另一个terminal,做同样的事情,我得到另一个窗口,以同一届会议。
有多个terminal窗口到同一个屏幕会话是非常好的,所以你可以同时看两个屏幕标签。
通过在我的服务器的〜/ .bashrc文件中放入以下内容,它将在我第一次login到服务器时启动一个屏幕会话,或者如果已经在运行,则重新连接到该会话。
我觉得这非常方便:
if [ -n "$SSH_CONNECTION" ] && [ -z "$SCREEN_EXIST" ]; then export SCREEN_EXIST=1 screen -DRi fi