Skip to content

Instantly share code, notes, and snippets.

@gtrabanco
Last active September 12, 2020 18:28
Show Gist options
  • Save gtrabanco/e5b942702549832cbbc8fb3896c73088 to your computer and use it in GitHub Desktop.
Save gtrabanco/e5b942702549832cbbc8fb3896c73088 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Github: github.com/gtrabanco
# Author: Gabriel Trabanco
# Website: gabi.io
# Description: This script append a publickey on UDMB/P because it deleted in every reboot/provision
# and I hate writing the password.
#
# You should have installed on_boot.d from https://github.com/boostchicken/udm-utilities/tree/master/on-boot-script
# and place the script in /mnt/data/on_boot.d after edit "MY_PUB_KEY" variable.
#
MY_PUB_KEY="Your public key here"
CRON_FILE="/etc/cron.d/S99-append-publickey"
function create_cron {
if [ ! -f $CRON_FILE ]; then
echo "*/10 * * * * /mnt/data/on_boot.d/S99-append-publickey.sh" > /etc/cron.d/S99-append-publickey
/etc/init.d/crond reload ${CRON_FILE}
fi
}
create_cron
if ! grep -q "$MY_PUB_KEY" "/root/.ssh/authorized_keys"; then
echo "$MY_PUB_KEY" >> /root/.ssh/authorized_keys
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment