Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
927 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...