diff --git a/src/freedombone-image b/src/freedombone-image index c972ea48..06271e45 100755 --- a/src/freedombone-image +++ b/src/freedombone-image @@ -58,6 +58,9 @@ DEFAULT_DOMAIN_NAME="${PROJECT_NAME}.local" # Minimum number of characters in a password MINIMUM_PASSWORD_LENGTH=10 +# Optional ssh public key to allow +SSH_PUBKEY="no" + while [[ $# > 1 ]] do key="$1" @@ -91,6 +94,10 @@ case $key in exit 3628 fi ;; + --sshkey|--sshpubkey|--pubkey) + shift + SSH_PUBKEY="$1" + ;; -s|--size) shift IMAGE_SIZE="$1" @@ -169,7 +176,8 @@ make $IMAGE_TYPE \ NAMESERVER2="$NAMESERVER2" \ PROJECT_NAME="$PROJECT_NAME" \ CONFIG_FILENAME="$CONFIG_FILENAME" \ - IMAGE_SIZE="$IMAGE_SIZE" + IMAGE_SIZE="$IMAGE_SIZE" \ + SSH_PUBKEY="$SSH_PUBKEY" shopt -s nullglob imgfiles=(build/${PROJECT_NAME}*.img) diff --git a/src/freedombone-image-customise b/src/freedombone-image-customise index 233f37e5..300335ef 100755 --- a/src/freedombone-image-customise +++ b/src/freedombone-image-customise @@ -47,6 +47,9 @@ NAMESERVER2='85.214.20.141' # optional configuration file containing freedombone settings CONFIG_FILENAME= +# Optional ssh public key to allow +SSH_PUBKEY="no" + enable_eatmydata_override() { chroot $rootdir apt-get install --no-install-recommends -y eatmydata if [ -x $rootdir/usr/bin/eatmydata ] && \ @@ -149,6 +152,20 @@ To complete the installation run the following: ' > $rootdir/etc/init.d/motd } +configure_ssh { + if [[ "$SSH_PUBKEY" != "no" ]]; then + if [ ! -d $rootdir/home/$MY_USERNAME/.ssh ]; then + mkdir $rootdir/home/$MY_USERNAME/.ssh + fi + echo "$SSH_PUBKEY" > $rootdir/home/$MY_USERNAME/.ssh/authorized_keys + chroot $rootdir chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh + sed -i 's|PasswordAuthentication.*|PasswordAuthentication no|g' $rootdir/etc/ssh/sshd_config + echo "Using ssh public key:" + echo $SSH_PUBKEY + echo 'Password ssh authentication turned off' + fi +} + continue_installation { # If a configuration file exists then run with it # otherwise the interactive installer can be used @@ -252,6 +269,7 @@ fi set_apt_sources $MIRROR chroot $rootdir apt-get update +configure_ssh configure_networking continue_installation diff --git a/src/freedombone-image-make b/src/freedombone-image-make index 7f2fc43d..40827b09 100755 --- a/src/freedombone-image-make +++ b/src/freedombone-image-make @@ -44,6 +44,7 @@ export NAMESERVER1 export NAMESERVER2 export PROJECT_NAME export CONFIG_FILENAME +export SSH_PUBKEY # Locate vmdebootstrap program fetched in Makefile basedir=`pwd` @@ -137,6 +138,7 @@ sudo sed -i "s|NAMESERVER1=.*|NAMESERVER1=${NAMESERVER1}|g" $TEMP_CUSTOMISE sudo sed -i "s|NAMESERVER2=.*|NAMESERVER2=${NAMESERVER1}|g" $TEMP_CUSTOMISE sudo sed -i "s|PROJECT_NAME=.*|PROJECT_NAME=${PROJECT_NAME}|g" $TEMP_CUSTOMISE sudo sed -i "s|CONFIG_FILENAME=.*|CONFIG_FILENAME=${CONFIG_FILENAME}|g" $TEMP_CUSTOMISE +sudo sed -i "s|SSH_PUBKEY=.*|SSH_PUBKEY=${SSH_PUBKEY}|g" $TEMP_CUSTOMISE echo "starting $VMDEBOOTSTRAP" # Run vmdebootstrap script to create image