Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 远程服务器上的多个ssh命令_Bash_Ssh - Fatal编程技术网

Bash 远程服务器上的多个ssh命令

Bash 远程服务器上的多个ssh命令,bash,ssh,Bash,Ssh,我们有一些带有动态RSA密钥的远程服务器用于登录 我想写一个脚本,让我可以执行一些需要很长时间的命令,也就是说,RSA密钥会在这两个命令之间进行更改 这可能吗 我现在有 scp file user@host:/path . #asks for password ssh user@host "command2" #asks for password 但我想要的是: # create some ssh connection to server (ask for password) scp_comm

我们有一些带有动态RSA密钥的远程服务器用于登录

我想写一个脚本,让我可以执行一些需要很长时间的命令,也就是说,RSA密钥会在这两个命令之间进行更改

这可能吗

我现在有

scp file user@host:/path . #asks for password
ssh user@host "command2" #asks for password
但我想要的是:

# create some ssh connection to server (ask for password)
scp_command1 #(doesn't need password)
# long time goes by
command2 #(doesn't need password)

您可以按以下方式运行这两个命令:

command1 && command2

这样,command1完成后command2就会启动。

我想您在命令中键入了一个
。此外,
command2
仅在
command1
以0退出代码完成时启动,这可能是或可能不是期望的行为。如果手动执行此操作,如何获得正确的密钥?您必须以某种方式自动执行该过程。如果在登录时密钥发生更改,您是否强制注销?如果没有,您可以使用
-M
选项在“主”模式下打开一个长期存在的连接,并将其用于其他连接。@chepner,我没有注销。请说明主模式连接是什么意思。当
ssh
在主模式下运行时,到同一主机的另一个连接可以“搭载”在主模式上,而无需重新验证。