Merge remote-tracking branch 'origin/github/pr/145'
[grml-live.git] / etc / grml / fai / config / scripts / GRMLBASE / 49-sshd
1 #!/bin/bash
2 # Filename:      ${GRML_FAI_CONFIG}/config/scripts/GRMLBASE/49-sshd
3 # Purpose:       adjust sshd configuration file
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 ################################################################################
8
9 set -u
10 set -e
11
12 if ! [ -r "${target}/etc/ssh/sshd_config" ] ; then
13   echo "File /etc/ssh/sshd_config doesn't exist, skipping execution of script."
14   exit 0
15 fi
16
17 # make sure root login works, it's set to "without-password" since openssh-server v1:6.6p1-1
18 # and defaults to "prohibit-password" since openssh-server v1:7.1p1-1
19 if grep -q '^PermitRootLogin ' "${target}/etc/ssh/sshd_config" ; then
20   # make sure we don't modify our own disabled snippet once again
21   if ! grep -q 'PermitRootLogin .*disabled via grml-live' "${target}/etc/ssh/sshd_config" ; then
22     sed -i "s/^\(PermitRootLogin .*\)/# \1 # disabled via grml-live\nPermitRootLogin yes/" "${target}/etc/ssh/sshd_config"
23   fi
24 else
25   echo "# Added via grml-live script:" >> "${target}/etc/ssh/sshd_config"
26   echo "PermitRootLogin yes" >> "${target}/etc/ssh/sshd_config"
27 fi
28
29 # speedup if DNS is broken/unavailable
30 if grep -q '^UseDNS ' "${target}/etc/ssh/sshd_config" ; then
31   # make sure we don't modify our own disabled snippet once again
32   if ! grep -q 'UseDNS .*disabled via grml-live' "${target}/etc/ssh/sshd_config" ; then
33     sed -i "s/^\(UseDNS .*\)/# \1 # disabled via grml-live\nUseDNS no/" "${target}/etc/ssh/sshd_config"
34   fi
35 else
36   echo "# Added via grml-live script:" >> "${target}/etc/ssh/sshd_config"
37   echo "UseDNS no" >> "${target}/etc/ssh/sshd_config"
38 fi
39
40 ## END OF FILE #################################################################
41 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2