Skip to content

Commit

Permalink
Allow SSH service to start if no PUBLIC_KEY is set
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleykleynhans committed Mar 9, 2024
1 parent fd169d6 commit 065ab20
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,41 @@ execute_script() {
fi
}

generate_ssh_host_keys() {
if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -q -N ''
fi

if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -q -N ''
fi

if [ ! -f /etc/ssh/ssh_host_ecdsa_key ]; then
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -q -N ''
fi

if [ ! -f /etc/ssh/ssh_host_ed25519_key ]; then
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -q -N ''
fi
}

setup_ssh() {
if [[ $PUBLIC_KEY ]]; then
# Add SSH public key from environment variable to ~/.ssh/authorized_keys
# if the PUBLIC_KEY environment variable is set
if [[ ${PUBLIC_KEY} ]]; then
echo "Setting up SSH..."
mkdir -p ~/.ssh
echo -e "${PUBLIC_KEY}\n" >> ~/.ssh/authorized_keys
chmod 700 -R ~/.ssh
fi

if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -q -N ''
fi

if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -q -N ''
fi

if [ ! -f /etc/ssh/ssh_host_ecdsa_key ]; then
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -q -N ''
fi

if [ ! -f /etc/ssh/ssh_host_ed25519_key ]; then
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -q -N ''
fi
# Generate SSH host keys if they don't exist
generate_ssh_host_keys

service ssh start
service ssh start

echo "SSH host keys:"
cat /etc/ssh/*.pub
fi
echo "SSH host keys:"
cat /etc/ssh/*.pub
}

export_env_vars() {
Expand Down

0 comments on commit 065ab20

Please sign in to comment.