次のコマンドを使用して、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.