unifios-utilities/on-boot-script/examples/udm-files/on_boot.d/15-add-root-ssh-key.sh
Jason Hobbs 8043e6ae6a
add support for multiple keys to be added; plus dropbear conversion (#192)
* add support for multiple keys to be added; converts private key to dropbear for unifi scp use

* change ssh id filename for dropbear default

using .ssh/id_dropbear is dropbear's default id file so no need to use 
`ssh -i /root/id_rsa`
any more.
2021-07-02 22:34:52 -07:00

32 lines
968 B
Bash

#!/bin/sh
#####################################################
# ADD RSA KEYS AS BELOW - CHANGE BEFORE RUNNING #
#####################################################
# set -- "ssh-rsa first key here all keys quoted" \ #
# "ssh-rsa each line appended with slash " \ #
# "ssh-rsa last one has no backslash" #
#####################################################
set -- "ssh-rsa AAAABUNCHOFCHARACTERSANDSTUFF me on MyMachine" \
"ssh-rsa AAAADIFFERENTKEYWITHCHARSETC! user@myhost"
KEYS_FILE="/root/.ssh/authorized_keys"
counter=0
for key in "$@"
do
## Places public key in ~/.ssh/authorized_keys if not present
if ! grep -Fxq "$key" "$KEYS_FILE"; then
let counter++
echo "$key" >> "$KEYS_FILE"
fi
done
echo $counter keys added to $KEYS_FILE
echo Converting SSH private key to dropbear format
#convert ssh key to dropbear for shell interaction
dropbearconvert openssh dropbear /mnt/data/ssh/id_rsa /root/.ssh/id_dropbear
exit 0;