bash 如何在两台远程机器之间使用 sshpass 复制数据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22962067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:09:49  来源:igfitidea点击:

How to copy data with sshpass between two remote machines?

linuxbashssh

提问by telina

I am new to bash and currently working on a script. I am working with two remote machines and accessing them via sshpass (I know its not good to hardcode passwords but I am supposed to do it this way). So if I want to copy stuff from my local machine to the remote one I am doing it like this:

我是 bash 新手,目前正在编写脚本。我正在使用两台远程机器并通过 sshpass 访问它们(我知道硬编码密码不好,但我应该这样做)。因此,如果我想将内容从本地机器复制到远程机器,我会这样做:

    sshpass -p $PASS scp <file> <destination>

But now I want to copy data from one remote machine to the other. Is this possible or do I have to buffer the data on my local machine? If its possible how should the syntax should look like? I would somehow need sshpass for both arguments, right?

但是现在我想将数据从一台远程机器复制到另一台机器。这是可能的还是我必须在本地机器上缓冲数据?如果可能的话,语法应该是什么样的?我会以某种方式需要 sshpass 来处理这两个参数,对吗?

采纳答案by BMW

can you ssh between two remote machines directly?

你可以直接在两台远程机器之间 ssh 吗?

run this from your local machine. (machine1 and mechine2 are remote servers)

从您的本地机器运行它。(machine1 和 mechine2 是远程服务器)

sshpass -p $PASS1 ssh user1@machine1 "sshpass -p $PASS2 scp file user2@machine2:/destination"

set keyless in ssh/scp between two remote servers and your local desktop to remote server. Then you needn't sshpass SSH login without password

在两台远程服务器和本地桌面到远程服务器之间的 ssh/scp 中设置无密钥。那么你不需要sshpass SSH 登录没有密码

ssh user1@machine1 "scp file user2@machine2:/destination"