correction ssh keygen
This commit is contained in:
parent
9c5a24f4b6
commit
4c582b4f6c
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. bin/setup_ssh_keys.sh
|
if [[ -n "$RECEIVING_IP" && -n "$RECEIVING_USER" && -n "$RECEIVING_PORT" ]]; then
|
||||||
|
if ssh -p $RECEIVING_PORT -q -o BatchMode=yes -o ConnectTimeout=5 $RECEIVING_USER@$RECEIVING_IP exit; then
|
||||||
install_pkg cron
|
install_pkg cron
|
||||||
|
|
||||||
cp ./assets/backup.sh ~/backup.sh
|
cp ./assets/backup.sh ~/backup.sh
|
||||||
|
|
@ -14,3 +14,8 @@ sed -i "s/^receiving_port=.*/receiving_port=$RECEIVING_PORT/" ~/backup.sh
|
||||||
cronjob="0 2 * * * ~/backup.sh"
|
cronjob="0 2 * * * ~/backup.sh"
|
||||||
|
|
||||||
( crontab -l 2>/dev/null; echo "$cronjob" ) | crontab -
|
( crontab -l 2>/dev/null; echo "$cronjob" ) | crontab -
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
. bin/setup_ssh_keys.sh
|
||||||
|
. bin/setup_backup.sh
|
||||||
|
fi
|
||||||
|
|
@ -7,6 +7,15 @@ read RECEIVING_USER
|
||||||
echo -e "${PURPLE}${BOLD}Enter the receiving server port : ${RESET}"
|
echo -e "${PURPLE}${BOLD}Enter the receiving server port : ${RESET}"
|
||||||
read RECEIVING_PORT
|
read RECEIVING_PORT
|
||||||
|
|
||||||
# si les ssh keys sont pas déjà set
|
if [ ! -f ~/.ssh/id_rsa ]; then
|
||||||
ssh-keygen
|
ssh-keygen -t rsa -b 2048 -N "" -f ~/.ssh/id_rsa
|
||||||
|
fi
|
||||||
ssh-copy-id -p ${RECEIVING_PORT} ${RECEIVING_USER}@${RECEIVING_IP}
|
ssh-copy-id -p ${RECEIVING_PORT} ${RECEIVING_USER}@${RECEIVING_IP}
|
||||||
|
|
||||||
|
hostname=$(hostname)
|
||||||
|
|
||||||
|
ssh -p $RECEIVING_PORT $RECEIVING_USER@$RECEIVING_IP << EOF
|
||||||
|
awk '/${hostname}$/ {last=\$0; count++} {lines[NR]=\$0} END {for (i=1; i<=NR; i++) if (lines[i] !~ /$(hostname)$/ || count-- == 1) print lines[i]}' /home/${RECEIVING_USER}/.ssh/authorized_keys
|
||||||
|
> /home/${RECEIVING_USER}/.ssh/authorized_keys.tmp
|
||||||
|
&& mv /home/${RECEIVING_USER}/.ssh/authorized_keys.tmp /home/${RECEIVING_USER}/.ssh/authorized_keys
|
||||||
|
EOF
|
||||||
Loading…
Reference in New Issue