Check for ssh public key

This commit is contained in:
Bob Mottram 2015-10-31 20:26:00 +00:00
parent 74673601e9
commit 1713d292d1
1 changed files with 13 additions and 11 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
MY_USERNAME=$1 MY_USERNAME=$1
SSH_PUBLIC_KEY=$2 SSH_PUBLIC_KEY="$2"
GPG_KEYSERVER='hkp://keys.gnupg.net' GPG_KEYSERVER='hkp://keys.gnupg.net'
SSH_PORT=2222 SSH_PORT=2222
COMPLETION_FILE=$HOME/freedombone-completed.txt COMPLETION_FILE=$HOME/freedombone-completed.txt
@ -30,19 +30,21 @@ if [ ! -d /home/$MY_USERNAME ]; then
exit 4 exit 4
fi fi
if [ $2 ]; then if [ "$SSH_PUBLIC_KEY" ]; then
if [ -f $SSH_PUBLIC_KEY ]; then if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
mkdir /home/$MY_USERNAME/.ssh if [ -f $SSH_PUBLIC_KEY ]; then
cp $SSH_PUBLIC_KEY /home/$MY_USERNAME/.ssh/authorized_keys
echo 'ssh public key installed'
else
if [[ $SSH_PUBLIC_KEY == "ssh-"* ]]; then
mkdir /home/$MY_USERNAME/.ssh mkdir /home/$MY_USERNAME/.ssh
echo $SSH_PUBLIC_KEY > /home/$MY_USERNAME/.ssh/authorized_keys cp $SSH_PUBLIC_KEY /home/$MY_USERNAME/.ssh/authorized_keys
echo 'ssh public key installed' echo 'ssh public key installed'
else else
echo 'The second parameter does not look like an ssh key' if [[ $SSH_PUBLIC_KEY == "ssh-"* ]]; then
exit 5 mkdir /home/$MY_USERNAME/.ssh
echo $SSH_PUBLIC_KEY > /home/$MY_USERNAME/.ssh/authorized_keys
echo 'ssh public key installed'
else
echo 'The second parameter does not look like an ssh key'
exit 5
fi
fi fi
fi fi
fi fi