Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # retrieve and change public keys from cron
- PATH='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'
- SCRIPT_PATH="${0}"
- ARGS="${#}"
- BACKUP='from="YOUR.IP.ADDRESS" ssh-dss <YOUR BACKUP PUB KEY> backup@backup-linux'
- # exit function
- function die() { echo -e "Error in ${SCRIPT_PATH}: ${1}"; exit 1; }
- # script depends on:
- [ -x /usr/bin/wget ] || die "This script depends on wget"
- # user must be root:
- [ $(whoami) = root ] || die "User must be root"
- # check for arguments:
- { [ ${ARGS} = 0 ]; } || die "Please dont feed me input"
- # get ldaphost
- [ -f /etc/uniqueidentifier ] || die "/etc/uniqueidentifier not found! please run the installer!"
- HOSTALIAS="$( cat /etc/uniqueidentifier | grep 'alias:' | cut -d':' -f2 )"
- HOSTIP="$( cat /etc/uniqueidentifier | grep 'ip:' | cut -d':' -f2 )"
- # get public key script from server
- wget -qq --no-check-certificate https://keyserver.example.com/keys/pubkey_manager --user=YOURUSER --password=YOURPASSWORD -O /tmp/pubkey_manager || die "failed to get keyscript"
- mv /tmp/pubkey_manager /usr/local/bin/pubkey_manager && chmod +x /usr/local/bin/pubkey_manager
- # get public ket from server
- wget -qq --no-check-certificate https://keyserver.example.com/keys/pubkeys/${HOSTALIAS}_id_rsa.pub --user=YOURUSER --password=YOURPASS -O /tmp/key.pub || die "Failed to get ssh key"
- # process
- [ -f /root/.ssh/authorized_keys ] && mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.old
- echo -e "${BACKUP}\nfrom=\"${HOSTIP}\" $( cat /tmp/key.pub )" >> /root/.ssh/authorized_keys && chmod 600 /root/.ssh/authorized_keys
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment