Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This 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!


  Search this Thread
Old 07-23-2010, 05:05 PM   #1
LQ Newbie
Registered: Jul 2010
Posts: 2

Rep: Reputation: 0
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.
Old 07-23-2010, 05:45 PM   #2
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
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.
Old 07-23-2010, 06:03 PM   #3
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590
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 ?
Old 07-23-2010, 06:13 PM   #4
Senior Member
Registered: Dec 2004
Posts: 1,055

Rep: Reputation: 78
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.
Old 07-28-2010, 03:32 PM   #5
LQ Newbie
Registered: Jul 2010
Posts: 2

Original Poster
Rep: Reputation: 0
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.
Old 07-28-2010, 05:00 PM   #6
Senior Member
Registered: Dec 2004
Posts: 1,055

Rep: Reputation: 78
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.
Old 07-28-2010, 10:42 PM   #7
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,034

Rep: Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407
The following should will do it.

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.




Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access compressed file without an intermediate student04 Linux - General 3 07-21-2010 01:50 AM
copying compiled program to another computer? babag Linux - Newbie 2 05-28-2008 06:41 PM
Help needed in removing intermediate segments from a pipe delimited segment file naren_0101bits Programming 12 12-03-2007 11:47 AM
COmputer crashes when copying files ApAdrian Linux - Networking 1 06-25-2007 10:30 AM
How do I change a root only file after I've messed it up and computer will not boot? SquishyMarbles Linux - General 2 09-07-2006 05:17 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:47 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration