Adding ssh keys via the user control panel

This commit is contained in:
Bob Mottram 2016-02-27 11:53:45 +00:00
parent caaaeac537
commit 021f5f9921
1 changed files with 35 additions and 0 deletions

View File

@ -410,6 +410,41 @@ function remove_gpg_key {
}
function add_ssh_key {
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --title $"Add your ssh public key" \
--backtitle $"Freedombone User Control Panel" \
--inputbox $"This will allow you to log into Freedombone if you have an ssh key on your system, and provides much stronger security than simply using a login password.\n\nWARNING: If you make any mistakes here then you may not be able to log in and will need to get the administrator to clear your ssh authorized_keys file." 15 60 2>$data
sel=$?
case $sel in
0)
SSH_PUBLIC_KEY=$(<$data)
if [ ${#SSH_PUBLIC_KEY} -gt 20 ]; then
if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
if [ ! -d /home/$USER/.ssh ]; then
mkdir /home/$USER/.ssh
fi
if [ ! -f /home/$USER/.ssh/authorized_keys ]; then
touch /home/$USER/.ssh/authorized_keys
fi
if ! grep -q "$SSH_PUBLIC_KEY" /home/$USER/.ssh/authorized_keys; then
echo "$SSH_PUBLIC_KEY" >> /home/$USER/.ssh/authorized_keys
dialog --title $"New ssh key added" \
--backtitle $"Freedombone User Control Panel" \
--msgbox $"Your ssh key has now been added" 6 50
else
dialog --title $"ssh key already added" \
--backtitle $"Freedombone User Control Panel" \
--msgbox $"That ssh key has already been added" 6 50
fi
else
dialog --title $"Unrecognised ssh public key" \
--backtitle $"Freedombone User Control Panel" \
--msgbox $"This doesn't look like an ssh key" 6 50
fi
fi
;;
esac
}
function remove_ssh_key {