Files
addons/ssh/run.sh
Pascal Vizeli 9699916301 Update addons with multibe tasks (#129)
Update addons with multibe tasks
2017-06-27 14:43:29 +02:00

32 lines
800 B
Bash

#!/bin/bash
set -e
CONFIG_PATH=/data/options.json
KEYS_PATH=/data/host_keys
AUTHORIZED_KEYS=$(jq --raw-output ".authorized_keys[]" $CONFIG_PATH)
# Init defaults config
sed -i s/#PermitRootLogin.*/PermitRootLogin\ yes/ /etc/ssh/sshd_config
sed -i s/#PasswordAuthentication.*/PasswordAuthentication\ no/ /etc/ssh/sshd_config
sed -i s/#LogLevel.*/LogLevel\ DEBUG/ /etc/ssh/sshd_config
# Generate authorized_keys file
mkdir -p ~/.ssh
while read -r line; do
echo "$line" >> ~/.ssh/authorized_keys
done <<< "$AUTHORIZED_KEYS"
chmod 600 ~/.ssh/authorized_keys
# Generate host keys
if [ ! -d "$KEYS_PATH" ]; then
mkdir -p "$KEYS_PATH"
ssh-keygen -A
cp -fp /etc/ssh/ssh_host* "$KEYS_PATH/"
else
cp -fp "$KEYS_PATH"/* /etc/ssh/
fi
# start server
exec /usr/sbin/sshd -D -e < /dev/null