brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: scp -3 copies between two remote hosts through your own machine

Network and access
~/tips/tip-scp-3-remote-to-remote

scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/

Copy a file from one server to another with scp, routed through the machine you type on

Copying a file from one server to another with scp sounds like the first server has to log in to the second one. Since OpenSSH 8.7 it doesn’t: scp sends the data through your own machine by default, and -3 asks for that route explicitly.

The command:

scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/

The data flows from server-a to your machine and on to server-b, and both logins use your own keys. On OpenSSH older than 8.7, leaving -3 out makes server-a connect to server-b directly, which needs credentials on server-a and network access between the two. ssh -V shows which version you have.

It also works when the two servers sit on networks that can’t reach each other, as long as your machine can reach both. Add -p to keep timestamps, or -C to compress the stream.

A caveat: everything travels through your connection twice, once down and once up. For a large file that can be slow. -R still asks for the direct route, but OpenSSH 10.6 started deprecating it and prints a warning. Newer OpenSSH versions use the SFTP protocol for scp by default, so a few old servers behave differently; -O switches back to the legacy protocol, and combined with -3 it can’t prompt for the second host’s password.

Further reading: scp(1) man page

More Network and access tips tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off caddy reverse-proxy --from :2016 --to :9000 All Network and access tips (163) All topics

Link