Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Commit f038cd1

Browse files
author
Timo Reichl
committed
Add SSHD for manipulating server files
Signed-off-by: Timo Reichl <[email protected]>
1 parent c50cc44 commit f038cd1

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

image/base/.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Dockerfile
1+
*
2+
!/etc
3+
!/usr

image/base/Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ RUN sed -i '/\[main\]/a install_weak_deps=False' /etc/dnf/dnf.conf && \
4343
# required packages for SteamCMD
4444
ncurses-libs.i686 \
4545
SDL2.i686 \
46+
# SSHD and editors for modifying server files externally
47+
openssh-server \
48+
vim \
49+
nano \
50+
&& \
51+
# Remve preinstalled SSHD configs but keep steamcmd.conf
52+
mv /etc/ssh/sshd_config.d/steamcmd.conf /tmp/steamcmd.conf && \
53+
rm -f /etc/ssh/sshd_config.d/* && \
54+
mv /tmp/steamcmd.conf /etc/ssh/sshd_config.d/steamcmd.conf \
4655
&& \
4756
# Update CA trust
4857
update-ca-trust \
@@ -86,7 +95,8 @@ RUN sed -i '/\[main\]/a install_weak_deps=False' /etc/dnf/dnf.conf && \
8695
/usr/bin/su \
8796
/usr/sbin/pam_timestamp_check \
8897
/usr/libexec/utempter/utempter \
89-
/usr/bin/write
98+
/usr/bin/write \
99+
/usr/libexec/openssh/ssh-keysign
90100

91101
# Switch to SteamCMD user
92102
USER steamcmd
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
PermitRootLogin no
2+
PubkeyAuthentication yes
3+
PasswordAuthentication no
4+
UsePAM yes
5+
6+
AuthorizedKeysFile %h/.ssh/authorized_keys
7+
8+
HostKey /opt/ssh/ssh_host_rsa_key
9+
HostKey /opt/ssh/ssh_host_ecdsa_key
10+
HostKey /opt/ssh/ssh_host_ed25519_key

image/games/base/docker-entrypoint.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
# Set original entrypoint
44
set -- tini -- start.sh ${@}
55

6+
# Helper function to fix host keys should they not exist
7+
prepare_ssh_host_key() {
8+
host_key_type="${1}"
9+
host_key_path="/opt/ssh/ssh_host_${host_key_type}_key"
10+
11+
if [[ ! -f ${host_key_path} ]]; then
12+
rm -f "${host_key_path}*"
13+
ssh-keygen -q -N "" -t ${host_key_type} -f ${host_key_path}
14+
fi
15+
}
16+
617
# Fix file and directory permissions if run as root
718
if [ $(id -u) -eq 0 ]; then
819

@@ -32,6 +43,31 @@ if [ $(id -u) -eq 0 ]; then
3243
mkdir -p ${tmux_socket_dir}
3344
chown -R steamcmd:steamcmd ${tmux_socket_dir}
3445

46+
if [[ "${STEAMCMD_SSH_SERVER_ENABLE}" == "1" ]]; then
47+
# Prepare SSH server
48+
echo "Preparing SSH server..."
49+
mkdir -p "${STEAMCMD_USER_HOME}/.ssh"
50+
51+
echo -n "${STEAMCMD_SSH_AUTHORIZED_KEYS}" | base64 -d > "${STEAMCMD_USER_HOME}/.ssh/authorized_keys"
52+
53+
if [ $? -ne 0 ]; then
54+
echo "${STEAMCMD_SSH_AUTHORIZED_KEYS}" > "${STEAMCMD_USER_HOME}/.ssh/authorized_keys"
55+
fi
56+
57+
chown -R steamcmd:steamcmd "${STEAMCMD_USER_HOME}/.ssh"
58+
chmod 0700 "${STEAMCMD_USER_HOME}/.ssh"
59+
chmod 0600 "${STEAMCMD_USER_HOME}/.ssh/authorized_keys"
60+
61+
mkdir -p /opt/ssh
62+
prepare_ssh_host_key "dsa"
63+
prepare_ssh_host_key "rsa"
64+
prepare_ssh_host_key "ecdsa"
65+
prepare_ssh_host_key "ed25519"
66+
67+
# Run the server
68+
/usr/sbin/sshd
69+
fi
70+
3571
# Call to gosu to drop from root user to steamcmd user
3672
# when running original entrypoint
3773
set -- gosu steamcmd $@

0 commit comments

Comments
 (0)