Parcourir la source

Fix ssh configuration

Bob Mottram il y a 8 ans
Parent
révision
b4a038b8c4
2 fichiers modifiés avec 12 ajouts et 0 suppressions
  1. 2
    0
      src/freedombone-image-customise
  2. 10
    0
      src/freedombone-utils-ssh

+ 2
- 0
src/freedombone-image-customise Voir le fichier

@@ -279,6 +279,7 @@ configure_ssh() {
279 279
     fi
280 280
 
281 281
     sed -i "s/Port .*/Port ${SSH_PORT}/g" $rootdir/etc/ssh/sshd_config
282
+    sed -i "s/#Port ${SSH_PORT}/Port ${SSH_PORT}/g" $rootdir/etc/ssh/sshd_config
282 283
 
283 284
     if [[ "$SSH_PUBKEY" != "no" ]]; then
284 285
         if [ ! -d $rootdir/home/$MY_USERNAME/.ssh ]; then
@@ -287,6 +288,7 @@ configure_ssh() {
287 288
         echo "$SSH_PUBKEY" > $rootdir/home/$MY_USERNAME/.ssh/authorized_keys
288 289
         chroot $rootdir /bin/chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
289 290
         sed -i 's|PasswordAuthentication.*|PasswordAuthentication no|g' $rootdir/etc/ssh/sshd_config
291
+        sed -i 's|#PasswordAuthentication no|PasswordAuthentication no|g' $rootdir/etc/ssh/sshd_config
290 292
         echo $"Using ssh public key:"
291 293
         echo $SSH_PUBKEY
292 294
         echo $'Password ssh authentication turned off'

+ 10
- 0
src/freedombone-utils-ssh Voir le fichier

@@ -41,10 +41,15 @@ function configure_ssh {
41 41
         return
42 42
     fi
43 43
     sed -i "s/Port .*/Port $SSH_PORT/g" /etc/ssh/sshd_config
44
+    sed -i "s/#Port ${SSH_PORT}/Port ${SSH_PORT}/g" /etc/ssh/sshd_config
44 45
     sed -i 's/PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
46
+    sed -i 's/#PermitRootLogin no/PermitRootLogin no/g' /etc/ssh/sshd_config
45 47
     sed -i 's/X11Forwarding.*/X11Forwarding no/g' /etc/ssh/sshd_config
48
+    sed -i 's/#X11Forwarding no/X11Forwarding no/g' /etc/ssh/sshd_config
46 49
     sed -i 's/ServerKeyBits.*/ServerKeyBits 4096/g' /etc/ssh/sshd_config
50
+    sed -i 's/#ServerKeyBits 4096/ServerKeyBits 4096/g' /etc/ssh/sshd_config
47 51
     sed -i 's/TCPKeepAlive.*/TCPKeepAlive no/g' /etc/ssh/sshd_config
52
+    sed -i 's/#TCPKeepAlive no/TCPKeepAlive no/g' /etc/ssh/sshd_config
48 53
     sed -i 's|HostKey /etc/ssh/ssh_host_dsa_key|#HostKey /etc/ssh/ssh_host_dsa_key|g' /etc/ssh/sshd_config
49 54
     sed -i 's|HostKey /etc/ssh/ssh_host_ecdsa_key|#HostKey /etc/ssh/ssh_host_ecdsa_key|g' /etc/ssh/sshd_config
50 55
     if ! grep -q 'DebianBanner' /etc/ssh/sshd_config; then
@@ -57,26 +62,31 @@ function configure_ssh {
57 62
     else
58 63
         echo 'ClientAliveInterval 60' >> /etc/ssh/sshd_config
59 64
     fi
65
+    sed -i 's/#ClientAliveInterval 60/ClientAliveInterval 60/g' /etc/ssh/sshd_config
60 66
     if grep -q 'ClientAliveCountMax' /etc/ssh/sshd_config; then
61 67
         sed -i 's/ClientAliveCountMax.*/ClientAliveCountMax 3/g' /etc/ssh/sshd_config
62 68
     else
63 69
         echo 'ClientAliveCountMax 3' >> /etc/ssh/sshd_config
64 70
     fi
71
+    sed -i 's/#ClientAliveCountMax 3/ClientAliveCountMax 3/g' /etc/ssh/sshd_config
65 72
     if grep -q 'Ciphers' /etc/ssh/sshd_config; then
66 73
         sed -i "s|Ciphers.*|Ciphers $SSH_CIPHERS|g" /etc/ssh/sshd_config
67 74
     else
68 75
         echo "Ciphers $SSH_CIPHERS" >> /etc/ssh/sshd_config
69 76
     fi
77
+    sed -i "s|#Ciphers $SSH_CIPHERS|Ciphers $SSH_CIPHERS|g" /etc/ssh/sshd_config
70 78
     if grep -q 'MACs' /etc/ssh/sshd_config; then
71 79
         sed -i "s|MACs.*|MACs $SSH_MACS|g" /etc/ssh/sshd_config
72 80
     else
73 81
         echo "MACs $SSH_MACS" >> /etc/ssh/sshd_config
74 82
     fi
83
+    sed -i "s|#MACs $SSH_MACS|MACs $SSH_MACS|g" /etc/ssh/sshd_config
75 84
     if grep -q 'KexAlgorithms' /etc/ssh/sshd_config; then
76 85
         sed -i "s|KexAlgorithms.*|KexAlgorithms $SSH_KEX|g" /etc/ssh/sshd_config
77 86
     else
78 87
         echo "KexAlgorithms $SSH_KEX" >> /etc/ssh/sshd_config
79 88
     fi
89
+    sed -i "s|#KexAlgorithms $SSH_KEX|KexAlgorithms $SSH_KEX|g" /etc/ssh/sshd_config
80 90
 
81 91
     apt-get -yq install fail2ban vim-common
82 92