Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 6
    +1 for explaining a valid use case (where the remote user on host1 has no permissions on the destination server); for the important security caveat (use port forwarding -D rather than -A to get around network rather than key restrictions); for explaining the advantage; for the command being short; and it actually working. Note that you may need to specify username@host1 if it's different from local username. Also that rsync performs host key verification when connecting to host2, so host1's key should already be in ~/.ssh/known_hosts on host2 or the command will fail. Commented Aug 21, 2017 at 8:21
  • Phenomenal answer, this helped me orchestrate some things in TeamCity that I wasn't able to do before (n.b. for other TeamCity users, you must add the "Build Feature" called "SSH agent" to your build config before using ssh -A, see confluence.jetbrains.com/display/TCD10/SSH+Agent). Commented Mar 7, 2018 at 10:15
  • 1
    You forgot to mention that this solution require host1 to have direct network access to host2, which a lot of the times is not the case. Commented Aug 19, 2021 at 1:52
  • 1
    This worked best for me. I did need to add my ssh key to the SSH Agent with ssh-add first. Commented Aug 26, 2021 at 16:20
  • @Kevin Cox >"why you didn't want to log into one host and then copy to the other" . This did the trick for me, thanks a lot! :) Commented Apr 15, 2022 at 9:12