2021-06-12 20:47:54 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# stdin: default config
|
|
|
|
# stdout: modified config
|
2021-07-02 12:50:24 +02:00
|
|
|
set -e
|
2021-06-12 20:47:54 +02:00
|
|
|
|
|
|
|
# save stdin (content of /etc/ssh/sshd_config) in variable
|
2021-07-02 12:50:24 +02:00
|
|
|
stdin="$(cat)"
|
2021-06-12 20:47:54 +02:00
|
|
|
|
2021-06-12 23:42:34 +02:00
|
|
|
# assertions
|
2021-07-02 12:50:24 +02:00
|
|
|
echo "=== assert UsePAM ===" 1>&2
|
2022-04-15 17:36:53 +02:00
|
|
|
echo "$stdin" | grep --quiet '^UsePAM[[:space:]]+yes$'
|
2021-06-12 20:47:54 +02:00
|
|
|
#
|
2021-07-02 12:50:24 +02:00
|
|
|
echo "=== assert PermitRootLogin ===" 1>&2
|
2022-04-15 17:36:53 +02:00
|
|
|
echo "$stdin" | grep --quiet '^#PermitRootLogin[[:space:]]*'
|
|
|
|
! echo "$stdin" | grep --quiet '^PermitRootLogin[[:space:]]+'
|
2021-07-02 12:50:24 +02:00
|
|
|
echo "=== assert PubkeyAuthentication ===" 1>&2
|
2022-04-15 17:36:53 +02:00
|
|
|
echo "$stdin" | grep --quiet '^#PubkeyAuthentication[[:space:]]*'
|
|
|
|
! echo "$stdin" | grep --quiet '^PubkeyAuthentication\[[:space:]]+'
|
2021-07-02 12:50:24 +02:00
|
|
|
echo "=== assert PasswordAuthentication ===" 1>&2
|
2022-04-15 17:36:53 +02:00
|
|
|
echo "$stdin" | grep --quiet '^#PasswordAuthentication[[:space:]]*'
|
|
|
|
! echo "$stdin" | grep --quiet '^PasswordAuthentication[[:space:]]+'
|
2021-07-02 12:50:24 +02:00
|
|
|
echo "=== assert PermitEmptyPasswords ===" 1>&2
|
2022-04-15 17:36:53 +02:00
|
|
|
echo "$stdin" | grep --quiet '^#PermitEmptyPasswords[[:space:]]*'
|
|
|
|
! echo "$stdin" | grep --quiet '^PermitEmptyPasswords[[:space:]]+'
|
2021-07-02 12:50:24 +02:00
|
|
|
echo "=== assert X11Forwarding ===" 1>&2
|
2022-04-15 17:36:53 +02:00
|
|
|
echo "$stdin" | grep --quiet '^#X11Forwarding[[:space:]]*'
|
|
|
|
! echo "$stdin" | grep --quiet '^X11Forwarding[[:space:]]+'
|
2021-06-12 20:47:54 +02:00
|
|
|
|
2021-07-02 12:50:24 +02:00
|
|
|
echo "=== sed ===" 1>&2
|
|
|
|
echo "$stdin" | sed '
|
2021-11-13 17:27:28 +01:00
|
|
|
s|^#PermitRootLogin\s.*$|PermitRootLogin yes|;
|
2021-07-02 12:50:24 +02:00
|
|
|
s|^#PubkeyAuthentication\s.*$|PubkeyAuthentication yes|;
|
|
|
|
s|^#PasswordAuthentication\s.*$|PasswordAuthentication no|;
|
|
|
|
s|^#PermitEmptyPasswords\s.*$|PermitEmptyPasswords no|;
|
|
|
|
s|^#X11Forwarding\s.*$|X11Forwarding no|
|
|
|
|
'
|