copy files using SSH from a server to another..both remote
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
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.
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
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
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?
Distribution: FC3, Manrake 10.x, various others at times
Posts: 113
Rep:
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:
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.