I regularly transfer files from a second remote host to my local machine. It would be nice to do this in one go! However, I need to load a key to connect to the second remote host.
Usually, the process is first to connect to the intermediate host:
ssh user@host1
(enter password)
I then load my private key and transfer the file from the third host to the second host:
exec ssh-agent bash
ssh-add ~/.ssh/id-privatekey
scp user@host2:filename filename
Then finally exit the second host and transfer the file from the second host to my local machine
exit
scp user@host2:filename filename
This is time-consuming, and a bit of a pain for large files where the disk space on host1 is limited.
The problem is similar to this question, so I tried:
ssh user@host1 'exec ssh-agent bash && ssh-add ~/.ssh/id-privatekey && ssh user@host2 "cat filename"' > filename
which seems to log into the first host, but nothing more. Please could anyone help?
question from:
https://stackoverflow.com/questions/65601669/how-do-i-scp-from-a-second-remote-host-that-requires-a-key-to-the-local-machin 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…