Skip to content

Commit e02ba19

Browse files
committed
Move everything out of the container filesystem into its own directories
1 parent 7129809 commit e02ba19

4 files changed

Lines changed: 35 additions & 22 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
338338

339339
## Versions
340340

341+
* **24.11.24:** - Move sshd_config to /config/sshd/sshd_config.
341342
* **31.05.24:** - Rebase to Alpine 3.20.
342343
* **04.05.24:** - Display the SSH host public keys every time the container starts.
343344
* **09.03.24:** - Rebase to Alpine 3.19.

readme-vars.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ app_setup_block: |
7272
The keys generated by this script are only displayed on your console output, so make sure to save them somewhere after generation.
7373
# changelog
7474
changelogs:
75+
- {date: "24.11.24:", desc: "Move sshd_config to /config/sshd/sshd_config."}
7576
- {date: "31.05.24:", desc: "Rebase to Alpine 3.20."}
7677
- {date: "04.05.24:", desc: "Display the SSH host public keys every time the container starts."}
7778
- {date: "09.03.24:", desc: "Rebase to Alpine 3.19."}

root/etc/s6-overlay/s6-rc.d/init-openssh-server-config/run

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# create folders
55
mkdir -p \
6-
/config/{.ssh,ssh_host_keys,logs/openssh}
6+
/config/{.ssh,logs/openssh,sshd}
77

88
USER_NAME=${USER_NAME:-linuxserver.io}
99
echo "User name is set to $USER_NAME"
@@ -30,15 +30,23 @@ fi
3030
USER_PASSWORD=${USER_PASSWORD:-$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c"${1:-8}";echo;)}
3131
echo "${USER_NAME}:${USER_PASSWORD}" | chpasswd
3232

33-
# symlink out ssh config directory
34-
if [[ ! -L /etc/ssh ]]; then
35-
if [[ ! -f /config/ssh_host_keys/sshd_config ]]; then
36-
sed -i '/#PidFile/c\PidFile \/config\/sshd.pid' /etc/ssh/sshd_config
37-
cp -a /etc/ssh/sshd_config /config/ssh_host_keys/
38-
fi
39-
rm -Rf /etc/ssh
40-
ln -s /config/ssh_host_keys /etc/ssh
33+
# Migration
34+
if [[ -f /config/ssh_host_keys/sshd_config ]]; then
35+
mv /config/ssh_host_keys/sshd_config /config/sshd/sshd_config
36+
sed -i 's/Include \/etc\/ssh\/sshd_config.d\/\*.conf/#Include \/etc\/ssh\/sshd_config.d\/\*.conf/' /config/sshd/sshd_config
37+
echo "This file has been moved to /config/sshd/sshd_config" > /config/ssh_host_keys/sshd_config_README
38+
fi
39+
40+
if [[ ! -f /config/sshd/sshd_config ]]; then
41+
sed -i '/#PidFile/c\PidFile \/config\/sshd.pid' /etc/ssh/sshd_config
42+
sed -i 's/Include \/etc\/ssh\/sshd_config.d\/\*.conf/#Include \/etc\/ssh\/sshd_config.d\/\*.conf/' /etc/ssh/sshd_config
43+
cp -a /etc/ssh/sshd_config /config/sshd/sshd_config
44+
fi
45+
46+
if [[ ! -d /config/ssh_host_keys ]]; then
47+
mkdir -p /config/ssh_host_keys
4148
ssh-keygen -A
49+
cp /etc/ssh/ssh_host_* /config/ssh_host_keys
4250
fi
4351

4452
# display SSH host public key(s)
@@ -47,32 +55,32 @@ cat /config/ssh_host_keys/ssh_host_*.pub
4755

4856
# custom port
4957
if [[ -n "${LISTEN_PORT}" ]]; then
50-
sed -i "s/^#Port [[:digit:]]\+/Port ${LISTEN_PORT}"/ /etc/ssh/sshd_config
51-
sed -i "s/^Port [[:digit:]]\+/Port ${LISTEN_PORT}"/ /etc/ssh/sshd_config
58+
sed -i "s/^#Port [[:digit:]]\+/Port ${LISTEN_PORT}"/ /config/sshd/sshd_config
59+
sed -i "s/^Port [[:digit:]]\+/Port ${LISTEN_PORT}"/ /config/sshd/sshd_config
5260
echo "sshd is listening on port ${LISTEN_PORT}"
5361
else
54-
sed -i "s/^#Port [[:digit:]]\+/Port 2222"/ /etc/ssh/sshd_config
55-
sed -i "s/^Port [[:digit:]]\+/Port 2222"/ /etc/ssh/sshd_config
62+
sed -i "s/^#Port [[:digit:]]\+/Port 2222"/ /config/sshd/sshd_config
63+
sed -i "s/^Port [[:digit:]]\+/Port 2222"/ /config/sshd/sshd_config
5664
echo "sshd is listening on port 2222"
5765
fi
5866

5967
# password access
6068
if [[ "$PASSWORD_ACCESS" == "true" ]]; then
61-
sed -i '/^#PasswordAuthentication/c\PasswordAuthentication yes' /etc/ssh/sshd_config
62-
sed -i '/^PasswordAuthentication/c\PasswordAuthentication yes' /etc/ssh/sshd_config
69+
sed -i '/^#PasswordAuthentication/c\PasswordAuthentication yes' /config/sshd/sshd_config
70+
sed -i '/^PasswordAuthentication/c\PasswordAuthentication yes' /config/sshd/sshd_config
6371
chown root:"${USER_NAME}" \
6472
/etc/shadow
6573
echo "User/password ssh access is enabled."
6674
else
67-
sed -i '/^PasswordAuthentication/c\PasswordAuthentication no' /etc/ssh/sshd_config
75+
sed -i '/^PasswordAuthentication/c\PasswordAuthentication no' /config/sshd/sshd_config
6876
chown root:root \
6977
/etc/shadow
7078
echo "User/password ssh access is disabled."
7179
fi
7280

7381
# set umask for sftp
7482
UMASK=${UMASK:-022}
75-
sed -i "s|/usr/lib/ssh/sftp-server$|/usr/lib/ssh/sftp-server -u ${UMASK}|g" /etc/ssh/sshd_config
83+
sed -i "s|/usr/lib/ssh/sftp-server$|/usr/lib/ssh/sftp-server -u ${UMASK}|g" /config/sshd/sshd_config
7684

7785
# set key auth in file
7886
if [[ ! -f /config/.ssh/authorized_keys ]]; then
@@ -133,10 +141,9 @@ chmod 700 \
133141
chmod 600 \
134142
/config/.ssh/authorized_keys
135143

136-
# ssh_host_keys permissions
137144
lsiown -R root:"${USER_NAME}" \
138-
/config/ssh_host_keys
145+
/config/sshd
139146
chmod 750 \
140-
/config/ssh_host_keys
147+
/config/sshd
141148
chmod 640 \
142-
/config/ssh_host_keys/*
149+
/config/sshd/sshd_config

root/etc/s6-overlay/s6-rc.d/svc-openssh-server/run

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
USER_NAME=${USER_NAME:-linuxserver.io}
55

6+
for i in /config/ssh_host_keys/ssh_host_*_key; do
7+
SSH_HOST_KEYS="${SSH_HOST_KEYS} -h ${i}"
8+
done
9+
610
exec 2>&1 \
711
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost ${LISTEN_PORT:-2222}" \
8-
s6-setuidgid "${USER_NAME}" /usr/sbin/sshd.pam -D -e
12+
s6-setuidgid "${USER_NAME}" /usr/sbin/sshd.pam -D -e -f /config/sshd/sshd_config ${SSH_HOST_KEYS}

0 commit comments

Comments
 (0)