Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
921 views
in Technique[技术] by (71.8m points)

ssh - How do I scp from a second remote host, that requires a key, to the local machine?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...