1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#!/bin/bash
BACKUPUSER=gldavid
PC_TARGET=remote
#Configuring the ssh connection.
#We need to send the rsa key to the remote account
if [ ! -f $HOME/.ssh/id_rsa.pub ]
then
echo "SSH configuration done"
ssh-keygen -t rsa -N "" -f $HOME/.ssh/id_rsa
echo "Generation of the key done"
fi
cat $HOME/.ssh/id_rsa.pub|ssh $BACKUPUSER@$PC_TARGET "cat >> .ssh/authorized_keys ; chmod 600 .ssh/authorized_keys"
if [ $? -ne 0 ]
then
if [ ! -d ~/tmp ]
then
mkdir ~/tmp
echo "tmp repertory creation"
fi
TMP=~/tmp/keepme$$
echo "SSH connection broken, trying to repare"
grep -v $PC_TARGET ~/.ssh/known_hosts > $TMP
mv $TMP ~/.ssh/known_hosts
cat $HOME/.ssh/id_rsa.pub|ssh $BACKUPUSER@$PC_TARGET "cat >> .ssh/authorized_keys ; chmod 600 .ssh/authorized_keys">&1
else
echo "SSH connection OK"
fi |
Partager