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! |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
07-09-2017, 11:43 AM
|
#1
|
LQ Newbie
Registered: Jul 2017
Posts: 29
Rep: 
|
Batching Copying Files Across Network
I've read a lot of posts on multiple sites about this, but not one post that seems to combine BOTH the ability to BATCH copy files over a network (i.e. scp) with a secure solution.
The goal is to routinely backup files from Linux box A to Linux box B via cron job. So obviously, entering a password isn't an option, and using a password-less login is of course not secure. So how best to get this done?
|
|
|
07-09-2017, 12:13 PM
|
#2
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
Usually rsync is a good way to go for transferring multiple files. The sftp program works, too, but cannot easily resume if interrupted. Both work over SSH so that means you can use keys.
Code:
rsync -a -v -H -e "ssh -i ~/.ssh/somekey.rsa" \
/source/dir/ user@remote.example.com:/dest/dir/
Usually if you do not use a passphrase on your key you should lock it down substantially with a forced command on the server. Otherwise, with a little bit of configuration, you can use an agent to hold the key for that connection.
|
|
|
07-09-2017, 12:28 PM
|
#3
|
LQ Newbie
Registered: Jul 2017
Posts: 29
Original Poster
Rep: 
|
Thanks. Since your post, I have been reading up on rsync and rsync_t and my eyes are glazing over. Seems pretty complicated.
|
|
|
07-09-2017, 12:33 PM
|
#4
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
You can go quite deep, but that is not really necessary. With password authentication, via SSH, you would run it like this:
Code:
rsync -a -v -H \
/source/dir/ user@remote.example.com:/dest/dir/
And to use a key see, the previous example in post #2.
Can you give more details about the transfer you have in mind and how you have used rsync so far. Also, how have you been using keys for regular SSH connections?
|
|
|
07-09-2017, 12:36 PM
|
#5
|
LQ Newbie
Registered: Jul 2017
Posts: 29
Original Poster
Rep: 
|
Thanks! I'll give it a try.
|
|
|
07-09-2017, 12:38 PM
|
#6
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
Passwordless SSH keys are not insecure. Its the standard way of unattended copying to remote hosts.
Set up your passwordless SSH keys under your preferred user: http://www.linuxproblem.org/art_9.html
That will probably save your key as .ssh/id_rsa.pub unless you specify otherwise.
Open up your cron as that user:
Code:
su - user1
crontab -e
add your rsync command to the cron and save (for example every 30 minutes):
Code:
*/30 * * * * rsync -varh -e "ssh -i ~/.ssh/id_rsa.pub" /local/source/dir/ remoteuser@remotemachine:/remote/dest/dir/
Keep in mind that the user you are setting SSH keys up for has to have permissions to the local files you are trying to copy.
|
|
|
07-09-2017, 12:41 PM
|
#7
|
LQ Newbie
Registered: Jul 2017
Posts: 29
Original Poster
Rep: 
|
Super, sz. I think I can handle this. I love this forum!
|
|
|
07-09-2017, 12:45 PM
|
#8
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
Quote:
Originally Posted by szboardstretcher
That will probably save your key as .ssh/id_rsa.pub unless you specify otherwise.
|
I'd recommend specifying a unique filename for the key pair so that later when you have more than one it will be easier to keep track of them. Likewise embedding a comment in the public key helps, too, once you have several public keys together. The -f and -C options do that. See "man sshkey-gen"
|
|
1 members found this post helpful.
|
07-09-2017, 12:47 PM
|
#9
|
LQ Newbie
Registered: Jul 2017
Posts: 29
Original Poster
Rep: 
|
Got it, thanks again!
|
|
|
All times are GMT -5. The time now is 12:18 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|