LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copying a file as root through an intermediate computer. (https://www.linuxquestions.org/questions/linux-newbie-8/copying-a-file-as-root-through-an-intermediate-computer-821770/)

quyzbuk 07-23-2010 04:05 PM

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.

bigrigdriver 07-23-2010 04:45 PM

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.

unSpawn 07-23-2010 05:03 PM

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 ?

sneakyimp 07-23-2010 05:13 PM

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.

quyzbuk 07-28-2010 02:32 PM

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.

Thank you very much for the replies.

sneakyimp 07-28-2010 04:00 PM

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.

evo2 07-28-2010 09:42 PM

The following should will do it.

Code:

ssh -f -N -L 9876:destinationhost:22 middlehost
scp -P 9876 somefile localhost:

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.

Cheers,

Evo2.


All times are GMT -5. The time now is 07:05 PM.