[sf-lug] question about using rsync and ssh in a script

John Magolske b79net at gmail.com
Sat Jul 10 09:40:51 PDT 2010


* Eric Walstad <eric at ericwalstad.com> [100709 21:36]:
> > I put together a simple script to rsync a couple directories of files
> > from a local machine up to a server using rsync & ssh
> ...
> > This ends up prompting me for the same password twice, and I'd like to
> > only have to input the password once.
> 
> How about not having to input the password at all?  If that's
> acceptable then you can use a public/private key pair to enable
> password-less logins.  Here's the script I use when creating new key
> pairs.  You'll want to edit the variables at the top to your taste
> before pasting the contents into a console on your (local) machine.
> 
> http://starship.python.net/crew/ewalstad/setup_ssh_keys.html

Thanks for the tips on using public/private key pairs with ssh, I'll
need to sit down & set this up at some point. For now I figured out
an rsync solution to syncing multiple directories without having to
re-input an entire rsync command. Rather than:

  #!/bin/sh
  rsync -av --delete -e ssh /path/to/site/ user at 123.456.78.900:dir/html
  rsync -av --delete -e ssh /path/to/files user at 123.456.78.900:dir

I tried this:

  #!/bin/sh
  rsync -av --delete -e ssh /path/to/{files,site/} user at 123.456.78.900:dir/html

Locally I have a symlink in the /path/to/site directory that links
to the /path/to/files directory. The above command would place that
symlink'd directory into the remote dir/html with everything else...
But then I found a more sensible solution:

  #!/bin/sh
  rsync -rkptgoDv --delete -e ssh /path/to/site/ user at 123.456.78.900:dir/html

The -a option is equivalent to -rlptgoD , so expanding that and
replacing the -l option with k "...causes the sending side to treat a
symlink to a directory as though it were a real directory" according
to rsync(1). Also, the ADVANCED USAGE section of that manpage has some
nice examples of how to specify multiple files & directories.

It'll probably make sense to sort out a public/private key solution at
some point, but this will do for now.

And thanks for the link Rick -- lots of useful stuff on that
http://linuxmafia.com/kb/Security Knowledgebase page.

Regards,

John


-- 
John Magolske
http://B79.net/contact




More information about the sf-lug mailing list