mgm-image/service.ssh.sh
Adam Štrauch 93a1cc2e36
All checks were successful
Build a dev image / build (push) Successful in 13s
Build a dev image / build (release) Successful in 15s
Update SSH service to change directory to /srv/stack before executing shell
2026-01-19 14:21:35 +01:00

34 lines
812 B
Bash

#!/bin/sh
if [ ! -e /etc/ssh/sshd_config ]; then
mkdir -p /etc/ssh/sshd_config.d
echo "Include /etc/ssh/sshd_config.d/*.conf
PermitRootLogin yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication yes
AllowTcpForwarding yes
GatewayPorts no
X11Forwarding no
Subsystem sftp internal-sftp" > /etc/ssh/sshd_config
fi
if [ -z "$SET_SHELL" ]; then
SET_SHELL="/bin/bash"
fi
if [ "$SET_SHELL" = "zsh" ]; then
SET_SHELL="/bin/zsh"
fi
if [ "$SET_SHELL" = "fish" ]; then
SET_SHELL="/usr/bin/fish"
fi
chsh -s $SET_SHELL
# Cloud image generates this file which prevents sshd from accepting passwords
rm -f /etc/ssh/sshd_config.d/50-cloud-init.conf
echo "ForceCommand cd /srv/stack; exec $SET_SHELL -l" > /etc/ssh/sshd_config.d/99-custom.conf
exec /usr/sbin/sshd -E /var/log/sshd.log -D