panubo / docker-sshd

Minimal Alpine Linux Docker image with sshd exposed and rsync installed
https://quay.io/repository/panubo/sshd
MIT License
448 stars 214 forks source link

Augtool breaks when mapping a local /etc/ssh/sshd_config as a volume #73

Open wharris1 opened 3 years ago

wharris1 commented 3 years ago

I've been able to run the image just fine --- doing various things. What I can't seem to do it is to replace its /etc/ssh/sshd_config with my own. Notice this is supported. The homepage says

Configure the container with the following environment variables or optionally mount a custom sshd config at /etc/ssh/sshd_config:

I'd like to replace it because I want to set directives such as ListenAddress. Whenever I try to replace it, I get the following error:

#docker run -v $(pwd)/sshd_config:/etc/ssh/sshd_config docker.io/panubo/sshd:latest
> Starting SSHD
>> Generating new host keys
ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519
error: Failed to execute command
saving failed (run 'errors' for details)
#

Output of DEBUG=true.

#docker run -v $(pwd)/sshd_config:/etc/ssh/sshd_config -e DEBUG=true docker.io/panubo/sshd:latest
> Starting SSHD
+ DAEMON=sshd
+ echo '> Starting SSHD'
++ ls -A /etc/ssh
>> Generating new host keys
+ '[' '!' 'moduli
ssh_config
sshd_config' ']'
+ ls '/etc/ssh/keys/ssh_host_*'
+ ls '/etc/ssh/ssh_host_*'
+ echo '>> Generating new host keys'
+ mkdir -p /etc/ssh/keys
+ ssh-keygen -A
ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519
+ mv /etc/ssh/ssh_host_dsa_key /etc/ssh/ssh_host_dsa_key.pub /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ed25519_key /etc/ssh/ssh_host_ed25519_key.pub /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_rsa_key.pub /etc/ssh/keys/
+ set_hostkeys
+ printf '%s\n' 'set /files/etc/ssh/sshd_config/HostKey[1] /etc/ssh/keys/ssh_host_rsa_key' 'set /files/etc/ssh/sshd_config/HostKey[2] /etc/ssh/keys/ssh_host_dsa_key' 'set /files/etc/ssh/sshd_config/HostKey[3] /etc/ssh/keys/ssh_host_ecdsa_key' 'set /files/etc/ssh/sshd_config/HostKey[4] /etc/ssh/keys/ssh_host_ed25519_key'
+ augtool -s
error: Failed to execute command
saving failed (run 'errors' for details)
#
nopoz commented 8 months ago

Execute a script when the container starts and modify the /etc/ssh/sshd_config file that way.

See the Custom Scripts section of the README for details.

Example script of enabling logging in /etc/ssh/sshd_config:

#!/usr/bin/env bash

# custom configuration /etc/ssh/sshd_config
ssh_config="/etc/ssh/sshd_config"
echo "customizing /etc/ssh/sshd_config..."
sed -i 's/^#SyslogFacility AUTH/SyslogFacility AUTH/' $ssh_config
sed -i 's/^#LogLevel INFO/LogLevel INFO/' $ssh_config