我使用以下命令直接在 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.