Copying a file as root through an intermediate computer.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Copying a file as root through an intermediate computer.
I am trying to copy four files from my machine, through a second machine, and finally to the destination. The destination computer can only be reached through the second computer, and I am curious to know if there is an easy way to do this. I am able to ssh to the middle machine and then ssh from there to the destination. I know that I could just copy from the first machine to the second, and then from there to the third. I guess that I'm curious to know what kind of command I can run to do this all at once or even if I could do such a thing (which I'm betting I can). Oh, I need to copy these files as root on the destination machine too.
I suppose there are more than one way to do it. The simplest way I know: write a shell script to copy the source file to the intermediate machine, then move it to the destination machine. (I assume you don't want to leave a trail of copied files on the intermediate machine).
Save the script. Any time you want to copy more files, just edit the script to change the name of the file to copy/move.
If you feel up to the challenge, write the script so that you can run the script and give it filenames as parameters (so that the filenames don't have to be hard coded into the script).
I also assume that you have root authority at each step along the way. You would have to run the script as root for it to work.
Configure a SSH LocalForward to the middle_machine on middle_port, configure a SSH connection on localhost and middle_port, then 'ssh -F some_configfile middle_machine' then 'ssh -F some_configfile localhost -p middle_port', see http://souptonuts.sourceforge.net/sshtips.htm ?
I'm wondering if you can ssh to the second machine then to the third machine and then use the scp command (secure copy) to retrieve the files from the first machine? You say the third machine is only reachable via the second machine, but the restrictions put in place may only apply to ssh access. That third machine may still be able to directly copy files to your first machine if your first machine has a publicly accessible IP address.
I'll have to check out the ssh forwarding when I have more time. I ended up just using scp to move files to the intermediate machine and then using scp again to the destination. I'm just looking for the laziest way to move them for future reference. =)
The destination machine is actually only wired to the intermediate machine.
Just to be clear...SCP works both ways. I realize you have to jump thru hoops to login to the destination machine, but once you have done so, you might be able to copy files directly from your original machine if it has a public ip address that is visible to the destination machine. The limitation of the destination machine may only be an SSH limitation, not a file-copy one.
The first command makes port 9876 point to port 22 (sshd) on the destinationhost (going via middlehost).
The second command will copy the file for from the localhost to destinationhost.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.