我使用以下命令直接在 Ubuntu 服务器上启动远程脚本/命令:
ssh me@server 'nano my_file.txt'
然而,这会引发一个错误:
Error opening terminal: unknown.
nano
另一个例子,调用包含上述命令的远程脚本也会出现同样的错误。
ssh me@server 'open_nano.sh'
当我这样做时ssh me@server 'echo something'
,我得到了something
预期的结果。
怎么了?
答案1
您必须使用旗帜-t
。
例子:
ssh -t me@server 'nano my_file.txt'
ssh -t me@server 'open_nano.sh'
解释来自man ssh
:
-t Force pseudo-tty allocation. This can be used to execute arbi‐ trary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.