单行ssh后的命令,需要交互输入怎么办?

Posted 王万林 Ben

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了单行ssh后的命令,需要交互输入怎么办?相关的知识,希望对你有一定的参考价值。

问题

单行ssh命令中,执行的命令又要交互输入,该怎么办?

~ ⌚ 21:48:55
$ ssh proxy-user@proxy-host "ssh wanlinwang@computing-host-001 hostname"
Warning: Permanently added 'proxy-host' (ED25519) to the list of known hosts.
proxy-user@proxy-host's password: 
Pseudo-terminal will not be allocated because stdin is not a terminal.
Permission denied, please try again.
Permission denied, please try again.
wanlinwang@computing-host-001: Permission denied (publickey,password).
~ ⌚ 21:49:12
$

解决

经查看ssh手册,可以加上-t选项,如下所示,

-t      Force pseudo-terminal allocation.  This can be used to execute arbitrary 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.

~ ⌚ 22:05:33
$ ssh -t proxy-user@proxy-host "ssh wanlinwang@computing-host-001 hostname"
proxy-user@proxy-host's password: 
wanlinwang@computing-host-001's password: 
computing-host-001
Connection to proxy-host closed.

~ ⌚ 22:05:48
$ 

以上是关于单行ssh后的命令,需要交互输入怎么办?的主要内容,如果未能解决你的问题,请参考以下文章