preserve ssh host keys across updates

fixes #2
This commit is contained in:
Girish Ramakrishnan 2016-05-03 22:49:59 -07:00
parent 0c58c963e9
commit bf698d28e4
2 changed files with 17 additions and 0 deletions

View file

@ -2,6 +2,7 @@ FROM cloudron/base:0.8.0
RUN apt-get update && \
apt-get install -y openssh-server && \
rm -rf /etc/ssh_host_* && \
rm -r /var/cache/apt /var/lib/apt/lists
ADD supervisor/ /etc/supervisor/conf.d/

View file

@ -29,8 +29,24 @@ if [[ -z "${SSH_PORT:-}" ]]; then
disable_ssh="true"
fi
if [[ ! -f "/app/data/sshd/ssh_host_ed25519_key" ]]; then
echo "Generating ssh host keys"
mkdir -p /app/data/sshd
ssh-keygen -qt rsa1 -N '' -f /app/data/sshd/ssh_host_key
ssh-keygen -qt rsa -N '' -f /app/data/sshd/ssh_host_rsa_key
ssh-keygen -qt dsa -N '' -f /app/data/sshd/ssh_host_dsa_key
ssh-keygen -qt ecdsa -N '' -f /app/data/sshd/ssh_host_ecdsa_key
ssh-keygen -qt ed25519 -N '' -f /app/data/sshd/ssh_host_ed25519_key
else
echo "Reusing existing host keys"
fi
chmod 0600 /app/data/sshd/*_key
chmod 0644 /app/data/sshd/*.pub
sed -e "s/^Port .*/Port ${SSH_PORT}/" \
-e "s/^#ListenAddress .*/ListenAddress 0.0.0.0/" \
-e "s,^HostKey /etc/ssh/,HostKey /app/data/sshd/," \
/etc/ssh/sshd_config > /run/gogs/sshd_config
sed -e "s/##DOMAIN/${APP_DOMAIN}/g" \