Changing ssh public key

This commit is contained in:
Bob Mottram 2015-11-01 10:51:54 +00:00
parent e5496d113b
commit 00f2a60585
1 changed files with 58 additions and 0 deletions

View File

@ -128,6 +128,64 @@ function change_password {
any_key
}
function change_ssh_public_key {
select_user
if [ ! $SELECTED_USERNAME ]; then
return
fi
if grep -Fxq "Admin user: $SELECTED_USERNAME" $COMPLETION_FILE; then
dialog --title "Change ssh public key" \
--backtitle "Freedombone Control Panel" \
--defaultno \
--yesno "\nThis is the administrator user.\n\nAre you sure you want to change the ssh public key for the administrator?" 10 60
sel=$?
case $sel in
1) return;;
255) return;;
esac
fi
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --title "Change ssh public key for $SELECTED_USERNAME" \
--backtitle "Freedombone Control Panel" \
--inputbox "Paste the ssh public key below" 8 60 2>$data
sel=$?
case $sel in
0)
SSH_PUBLIC_KEY=$(<$data)
if [ "$SSH_PUBLIC_KEY" ]; then
if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
if [ -f "$SSH_PUBLIC_KEY" ]; then
if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
mkdir /home/$SELECTED_USERNAME/.ssh
fi
cp $SSH_PUBLIC_KEY \
/home/$SELECTED_USERNAME/.ssh/authorized_keys
chown -R $SELECTED_USERNAME:$SELECTED_USERNAME \
/home/$SELECTED_USERNAME/.ssh
dialog --title "Change ssh public key" \
--msgbox "ssh public key was installed" 6 40
else
if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
mkdir /home/$SELECTED_USERNAME/.ssh
fi
echo "$SSH_PUBLIC_KEY" > \
/home/$SELECTED_USERNAME/.ssh/authorized_keys
chown -R $SELECTED_USERNAME:$SELECTED_USERNAME \
/home/$SELECTED_USERNAME/.ssh
dialog --title "Change ssh public key" \
--msgbox "ssh public key was installed" 6 40
fi
fi
fi
fi
;;
esac
}
function add_to_mailing_list {
select_user
if [ ! $SELECTED_USERNAME ]; then