Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

passwd when using rsync -e ssh (solved)

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
User avatar
nadir
Posts: 5961
Joined: 2009-10-05 22:06
Location: away

passwd when using rsync -e ssh (solved)

#1 Post by nadir »

I already wrote this post, then the laptop shut-down. So here is the short version:
After backing up the OS via rsync over the Lan to the second PC i want to rsync a few user-folders.
I often forget it (shutdown the source PC, shutdown the LIve-CD, oh?forgotten :evil: : shut on everything again...) so i wrote a few lines to put it in a file/script.

I have thought it would be ok, but i need to re-enter the passwd for rsync/ssh for each folder i rsync.
Is there a way around that (besides doing it with exclude. In this case i don't want to use exclude).
Thanks.

Here is the script (like said, i just smashed it together).
The rsync is at the bottom (the rest is chat) for each rsync i need to enter the passwd.
Besides that it does what needs to be done.

Code: Select all

#!/usr/bin/env/bash
# set -e 
clear; echo 
date
###############
# VARIABLES
##############

SOURCE="m1arkust@debian-sid:/home/m1arkust"
TARGET="/media/backup/home/m1arkust"

echo "
    The sources are:
    $SOURCE/Documents
    $SOURCE/Pictures
    $SOURCE/bin
    $SOURCE/Programming

    The targets are:

    $TARGET/Documents
    $TARGET/Pictures
    $TARGET/bin
    $TARGET/Programming "
echo 

############################
# FUNKTION asks for going on
############################

function ask_for {
echo -n "
    You want to go on?
        Say yes or no: "

read answer
case $answer in 
[Yy]es | [Yy] )  echo "ok: ";;
*) echo "
    You didn't answer yes.
    The script will die."
  exit 0
esac
}

ask_for


################
# RSYNCING
###############
rsync -e ssh -auv --delete-after "$SOURCE"/Documents/* "$TARGET"/Documents

rsync -e ssh -auv --delete-after --exclude="photos" "$SOURCE"/Pictures/* "$TARGET"/Pictures

rsync -e ssh -auv --delete-after "$SOURCE"/bin/* "$TARGET"/bin 

rsync -e ssh -auv --delete-after --exclude="Bash/Git/git"  "$SOURCE"/Programming/* "$TARGET"/Programming

notify-send "Done"

exit 0
No biggie, just a simple question if someone has got an easy idea how to solve it.
Might rather be a rsync than a programming question. Just move it around if that is the case.
Thanks
Last edited by nadir on 2010-08-30 01:23, edited 1 time in total.
"I am not fine with it, so there is nothing for me to do but stand aside." M.D.

smallchange
Posts: 1740
Joined: 2009-05-04 15:56
Been thanked: 1 time

Re: passwd when using rsync -e ssh

#2 Post by smallchange »

That sounds like a job for keychain. I will keep your ssh agent active so scripts or cron jobs can run without entering the password.

I use this in my .bashrc where I want to to be active.

Code: Select all

# If keychain is running source the file to take advantage of it
if [ -e ~/.keychain/`uname -n`-sh ] ; then
    . ~/.keychain/`uname -n`-sh;
    else
    if [ -e /usr/bin/keychain ] ; then
        keychain ~/.ssh/id_rsa
        . ~/.keychain/`uname -n`-sh
    fi
fi
I also remove them on reboot by adding code to /etc/rc.local

Code: Select all

# remove stale .keychain files on boot
HOST=`hostname -s`
for user in `ls /home`; do
    if [ -f /home/$user/.keychain/$HOST-sh ]; then
        rm /home/$user/.keychain/$HOST*
    fi
done

User avatar
nadir
Posts: 5961
Joined: 2009-10-05 22:06
Location: away

Re: passwd when using rsync -e ssh

#3 Post by nadir »

I didn't get it running yet.
I installed keychain and ssh-askpass, edited my .bashrc and tried. I had to re-enter the pubkey-password :( I rebooted and tried again: same thing.
When nothing helps there is the man page. I found the option: "--password-file file_name" for rsync, tried that, but it told me i would not be connecting to an rsync-daemon.

Will try again tomorrow, or when i got time.
Thanks for your answer.
"I am not fine with it, so there is nothing for me to do but stand aside." M.D.

smallchange
Posts: 1740
Joined: 2009-05-04 15:56
Been thanked: 1 time

Re: passwd when using rsync -e ssh

#4 Post by smallchange »

The idea of it is to start keychain and load a key with

Code: Select all

keychain ~/.ssh/id_rsa
and then source the .keychain file created so that you will have keychain running with the appropriate agent. Then each additional shell can source that .keychain file to use it also. That is what the .bashrc code does. If the .keychain/`uname -n`-sh file exists, source it, if not start keychain, which asks for the pass phrase, and then source the file. The purpose for removing the .keychain/`uname -n`-sh on reboot is that it points to an old agent so you need to start it again.

User avatar
nadir
Posts: 5961
Joined: 2009-10-05 22:06
Location: away

Re: passwd when using rsync -e ssh (solved)

#5 Post by nadir »

Ok, that made it more clear.
I did try a bit (i am never that sure what is exactly getting sourced when and why), also edited local.rc and then, after reboot, it did work.
(with a bit of fiddling i should be able to add it my Live-CD and voila: another good tool)
Hurray.

That was a great tip (i checked the german ubuntu-wiki, it is quite elaborate, but even they don't tell about it).
Thank you :-)
"I am not fine with it, so there is nothing for me to do but stand aside." M.D.

ychaouche
Posts: 87
Joined: 2014-12-11 09:45

Re: passwd when using rsync -e ssh (solved)

#6 Post by ychaouche »

I would personnaly use non-password-protected ssh-keys. No passwords asked and it's very easy to setup.

Code: Select all

$ ssh-keygen             #<----- this will generate the necessary keys
$ ssh-copy-id remotehost #<----- This will do the necessary job to allow key-based authentication between this machine and the remotehost.
Done. Now you (and this includes rsync) can ssh to remotehost without any questions asked.

Post Reply