LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 03-09-2004, 11:23 PM   #1
Santosh_d
LQ Newbie
 
Registered: Mar 2004
Location: Pune,India
Distribution: RedHat 8.0
Posts: 14

Rep: Reputation: 0
copy files using SSH from a server to another..both remote


i have 2 remote servers. i want to connect from a third machine to the first server using ssh and copy some files from this server to the second server from the third machine itself.
can i automate this process using cron?
pls provide a step by step procedure to do this.
thanx
Regards
 
Old 03-10-2004, 12:15 AM   #2
mardanian
Member
 
Registered: Mar 2004
Distribution: Fedora
Posts: 254

Rep: Reputation: 30
to copy file remotely and securely, use scp below is the generally usage
note: i am using IPs instead of hostnames and also assumes I am on first server.

$scp filename 203.156.69.4:/tmp/

the above command will copy the file from frist server to second servers /tmp direcotory

Yes you can automate the task using cron.

enjoy
 
Old 03-10-2004, 12:49 AM   #3
Santosh_d
LQ Newbie
 
Registered: Mar 2004
Location: Pune,India
Distribution: RedHat 8.0
Posts: 14

Original Poster
Rep: Reputation: 0
but then do i need to establish a ssh connection before issuing the scp command?
also can i get a method to extract a file using ssh from a remote server i.e. can i put a cron job to extract a file from a remote server on my server?
 
Old 03-10-2004, 11:23 AM   #4
shubb
Member
 
Registered: Oct 2003
Location: San Francisco
Distribution: Slackware 13.37
Posts: 150

Rep: Reputation: 16
The scp command automatically uses ssh to copy. You can use scp to either copy to, or from a remote machine.

the syntax is:

scp <source file> <destination file>

Depending on whether you are copying to, or from, you put the remote file either in the source or destination file.

For example:

scp localfile 10.1.1.1:/remotefile

or

scp 10.1.1.1:/remotefile localfile
 
Old 03-10-2004, 04:17 PM   #5
lnxconvrt
Member
 
Registered: Mar 2002
Location: Houston
Distribution: FC3, Manrake 10.x, various others at times
Posts: 113

Rep: Reputation: 18
scp and passwordless keys

The other posts are accurate. As noted, scp actually does an ssh login to do the copy. So, to use ssh as a user named bigdog to transfer a file named /home/poodle/test from a host named dog to /home/persian on a host named cat using user littlecat to log into cat, do this:

scp bigdog@dog:/home/poodle/test littlecat@cat:/home/persian

You would have to enter the passwords for both users.

If you don't specify a user scp will assume you are logging in to remote machines as the same user as is currently logged in to the local machine. So, if you are root and don't specify the "username@" it would assume "root@" and ask for the root password of the remote machine.

So, to do this with a cron job, and assuming that you are logging in as root you have the problem of not being there to enter the root password. The way around this is to use ssh-keygen to generate a passwordless key. IIRC something like "ssh-keygen -t dsa -o filename" should generate a public key/private key pair of type dsa and put them in filename.pub and filename, respectively. If you don't use "-o" the default is to name them id_dsa and id_dsa.pub.

You generate these keys on the host that you want to run the cron job on. You then put the public key in the ~root/.ssh/authorized_keys file of the hosts that you want to copy to/from and they will trust the first machine to allow scp without someone there to input the root password.

Whew! This reply turned into a bit of a book. If it's not clear you can probably find a how-to that will explain it better and in more detail. A google for something like "passwordless ssh authorized_keys" might do it, but I need to get back to work for now.
 
Old 03-10-2004, 08:45 PM   #6
darkseed2g3
Member
 
Registered: Sep 2003
Location: Philadelphia ,Pa
Distribution: Fedora Core 1 BABY !!! YEA
Posts: 67

Rep: Reputation: 19
to do SSH password-less entries you have to first create your keys , one private and one public with this command

ssh-keygen -t rsa

for most default machines you can simply answer yes to all the files

now you wanna scp like this

scp /root/.ssh/id_rsa.pub remotemacine:/root/.ssh/autorized_keys2

it will ask your a password , but that will be the last time it does. If you want some more ssh uses check out the faqs, man pages and a good book is 101 hacks for the linux server it was a great read
 
Old 03-10-2004, 11:02 PM   #7
Santosh_d
LQ Newbie
 
Registered: Mar 2004
Location: Pune,India
Distribution: RedHat 8.0
Posts: 14

Original Poster
Rep: Reputation: 0
Smile

thanx everybody...its pretty clear now...
thanx for the help
Regards
 
  


Reply


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
scp/ssh tail(multiple file) remote copy tpreitano Linux - General 1 08-22-2005 02:17 PM
how to copy files from a remote server man1979 Linux - General 3 08-16-2005 06:08 AM
SSH and remote files yeti.man Linux - Networking 3 09-11-2004 01:08 AM
copy from remote with ssh mehlkelm Linux - Networking 4 09-02-2004 08:11 AM
copy files from a server to another..both remote Santosh_d Linux - Networking 1 03-09-2004 07:52 AM


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

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