Skip to content

Commit 42e3093

Browse files
authored
Merge pull request #97 from linuxserver/mild-despair
2 parents 8e4cd2e + 1383ead commit 42e3093

5 files changed

Lines changed: 43 additions & 23 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-adduser/run

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/usr/bin/with-contenv bash
22
# shellcheck shell=bash
33

4-
USER_NAME=${USER_NAME:-linuxserver.io}
4+
if [[ -n "$USER_NAME" ]] && [[ "$USER_NAME" != "abc" ]] && grep -q "^${USER_NAME}" /etc/passwd; then
5+
echo "*** USER_NAME cannot be set to an user that already exists in /etc/passwd. Halting init. ***"
6+
sleep infinity
7+
else
8+
USER_NAME=${USER_NAME:-linuxserver.io}
9+
fi
510

611
PUID=${PUID:-911}
712
PGID=${PGID:-911}

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

Lines changed: 30 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,25 @@ 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+
chmod 600 /config/sshd/sshd_config/ssh_host_*_key
39+
chmod 644 /config/sshd/sshd_config/ssh_host_*_key.pub
40+
fi
41+
42+
if [[ ! -f /config/sshd/sshd_config ]]; then
43+
sed -i '/#PidFile/c\PidFile \/config\/sshd.pid' /etc/ssh/sshd_config
44+
sed -i 's/Include \/etc\/ssh\/sshd_config.d\/\*.conf/#Include \/etc\/ssh\/sshd_config.d\/\*.conf/' /etc/ssh/sshd_config
45+
cp -a /etc/ssh/sshd_config /config/sshd/sshd_config
46+
fi
47+
48+
if [[ ! -d /config/ssh_host_keys ]]; then
49+
mkdir -p /config/ssh_host_keys
4150
ssh-keygen -A
51+
cp /etc/ssh/ssh_host_* /config/ssh_host_keys
4252
fi
4353

4454
# display SSH host public key(s)
@@ -47,32 +57,32 @@ cat /config/ssh_host_keys/ssh_host_*.pub
4757

4858
# custom port
4959
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
60+
sed -i "s/^#Port [[:digit:]]\+/Port ${LISTEN_PORT}"/ /config/sshd/sshd_config
61+
sed -i "s/^Port [[:digit:]]\+/Port ${LISTEN_PORT}"/ /config/sshd/sshd_config
5262
echo "sshd is listening on port ${LISTEN_PORT}"
5363
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
64+
sed -i "s/^#Port [[:digit:]]\+/Port 2222"/ /config/sshd/sshd_config
65+
sed -i "s/^Port [[:digit:]]\+/Port 2222"/ /config/sshd/sshd_config
5666
echo "sshd is listening on port 2222"
5767
fi
5868

5969
# password access
6070
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
71+
sed -i '/^#PasswordAuthentication/c\PasswordAuthentication yes' /config/sshd/sshd_config
72+
sed -i '/^PasswordAuthentication/c\PasswordAuthentication yes' /config/sshd/sshd_config
6373
chown root:"${USER_NAME}" \
6474
/etc/shadow
6575
echo "User/password ssh access is enabled."
6676
else
67-
sed -i '/^PasswordAuthentication/c\PasswordAuthentication no' /etc/ssh/sshd_config
77+
sed -i '/^PasswordAuthentication/c\PasswordAuthentication no' /config/sshd/sshd_config
6878
chown root:root \
6979
/etc/shadow
7080
echo "User/password ssh access is disabled."
7181
fi
7282

7383
# set umask for sftp
7484
UMASK=${UMASK:-022}
75-
sed -i "s|/usr/lib/ssh/sftp-server$|/usr/lib/ssh/sftp-server -u ${UMASK}|g" /etc/ssh/sshd_config
85+
sed -i "s|/usr/lib/ssh/sftp-server$|/usr/lib/ssh/sftp-server -u ${UMASK}|g" /config/sshd/sshd_config
7686

7787
# set key auth in file
7888
if [[ ! -f /config/.ssh/authorized_keys ]]; then
@@ -133,10 +143,9 @@ chmod 700 \
133143
chmod 600 \
134144
/config/.ssh/authorized_keys
135145

136-
# ssh_host_keys permissions
137146
lsiown -R root:"${USER_NAME}" \
138-
/config/ssh_host_keys
147+
/config/sshd
139148
chmod 750 \
140-
/config/ssh_host_keys
149+
/config/sshd
141150
chmod 640 \
142-
/config/ssh_host_keys/*
151+
/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)