|
@@ -30,113 +30,113 @@
|
30
|
30
|
|
31
|
31
|
SSH_PORT=2222
|
32
|
32
|
|
33
|
|
-# ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
|
34
|
|
-SSH_CIPHERS="chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr"
|
35
|
|
-SSH_MACS="hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,umac-128@openssh.com"
|
36
|
|
-SSH_KEX="curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256"
|
|
33
|
+# Settings from bettercrypto.org
|
|
34
|
+SSH_CIPHERS="aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes128-ctr"
|
|
35
|
+SSH_MACS="hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160"
|
|
36
|
+SSH_KEX="diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1"
|
37
|
37
|
SSH_HOST_KEY_ALGORITHMS="ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-ed25519,ssh-rsa"
|
38
|
38
|
|
39
|
39
|
function configure_ssh {
|
40
|
|
- if grep -Fxq "configure_ssh" $COMPLETION_FILE; then
|
41
|
|
- return
|
42
|
|
- fi
|
43
|
|
- sed -i "s/Port .*/Port $SSH_PORT/g" /etc/ssh/sshd_config
|
44
|
|
- sed -i 's/PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
|
45
|
|
- sed -i 's/X11Forwarding.*/X11Forwarding no/g' /etc/ssh/sshd_config
|
46
|
|
- sed -i 's/ServerKeyBits.*/ServerKeyBits 4096/g' /etc/ssh/sshd_config
|
47
|
|
- sed -i 's/TCPKeepAlive.*/TCPKeepAlive no/g' /etc/ssh/sshd_config
|
48
|
|
- sed -i 's|HostKey /etc/ssh/ssh_host_dsa_key|#HostKey /etc/ssh/ssh_host_dsa_key|g' /etc/ssh/sshd_config
|
49
|
|
- sed -i 's|HostKey /etc/ssh/ssh_host_ecdsa_key|#HostKey /etc/ssh/ssh_host_ecdsa_key|g' /etc/ssh/sshd_config
|
50
|
|
- if ! grep -q 'DebianBanner' /etc/ssh/sshd_config; then
|
51
|
|
- echo 'DebianBanner no' >> /etc/ssh/sshd_config
|
52
|
|
- else
|
53
|
|
- sed -i 's|DebianBanner.*|DebianBanner no|g' /etc/ssh/sshd_config
|
54
|
|
- fi
|
55
|
|
- if grep -q 'ClientAliveInterval' /etc/ssh/sshd_config; then
|
56
|
|
- sed -i 's/ClientAliveInterval.*/ClientAliveInterval 60/g' /etc/ssh/sshd_config
|
57
|
|
- else
|
58
|
|
- echo 'ClientAliveInterval 60' >> /etc/ssh/sshd_config
|
59
|
|
- fi
|
60
|
|
- if grep -q 'ClientAliveCountMax' /etc/ssh/sshd_config; then
|
61
|
|
- sed -i 's/ClientAliveCountMax.*/ClientAliveCountMax 3/g' /etc/ssh/sshd_config
|
62
|
|
- else
|
63
|
|
- echo 'ClientAliveCountMax 3' >> /etc/ssh/sshd_config
|
64
|
|
- fi
|
65
|
|
- if grep -q 'Ciphers' /etc/ssh/sshd_config; then
|
66
|
|
- sed -i "s|Ciphers.*|Ciphers $SSH_CIPHERS|g" /etc/ssh/sshd_config
|
67
|
|
- else
|
68
|
|
- echo "Ciphers $SSH_CIPHERS" >> /etc/ssh/sshd_config
|
69
|
|
- fi
|
70
|
|
- if grep -q 'MACs' /etc/ssh/sshd_config; then
|
71
|
|
- sed -i "s|MACs.*|MACs $SSH_MACS|g" /etc/ssh/sshd_config
|
72
|
|
- else
|
73
|
|
- echo "MACs $SSH_MACS" >> /etc/ssh/sshd_config
|
74
|
|
- fi
|
75
|
|
- if grep -q 'KexAlgorithms' /etc/ssh/sshd_config; then
|
76
|
|
- sed -i "s|KexAlgorithms.*|KexAlgorithms $SSH_KEX|g" /etc/ssh/sshd_config
|
77
|
|
- else
|
78
|
|
- echo "KexAlgorithms $SSH_KEX" >> /etc/ssh/sshd_config
|
79
|
|
- fi
|
|
40
|
+ if grep -Fxq "configure_ssh" $COMPLETION_FILE; then
|
|
41
|
+ return
|
|
42
|
+ fi
|
|
43
|
+ sed -i "s/Port .*/Port $SSH_PORT/g" /etc/ssh/sshd_config
|
|
44
|
+ sed -i 's/PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
|
|
45
|
+ sed -i 's/X11Forwarding.*/X11Forwarding no/g' /etc/ssh/sshd_config
|
|
46
|
+ sed -i 's/ServerKeyBits.*/ServerKeyBits 4096/g' /etc/ssh/sshd_config
|
|
47
|
+ sed -i 's/TCPKeepAlive.*/TCPKeepAlive no/g' /etc/ssh/sshd_config
|
|
48
|
+ sed -i 's|HostKey /etc/ssh/ssh_host_dsa_key|#HostKey /etc/ssh/ssh_host_dsa_key|g' /etc/ssh/sshd_config
|
|
49
|
+ sed -i 's|HostKey /etc/ssh/ssh_host_ecdsa_key|#HostKey /etc/ssh/ssh_host_ecdsa_key|g' /etc/ssh/sshd_config
|
|
50
|
+ if ! grep -q 'DebianBanner' /etc/ssh/sshd_config; then
|
|
51
|
+ echo 'DebianBanner no' >> /etc/ssh/sshd_config
|
|
52
|
+ else
|
|
53
|
+ sed -i 's|DebianBanner.*|DebianBanner no|g' /etc/ssh/sshd_config
|
|
54
|
+ fi
|
|
55
|
+ if grep -q 'ClientAliveInterval' /etc/ssh/sshd_config; then
|
|
56
|
+ sed -i 's/ClientAliveInterval.*/ClientAliveInterval 60/g' /etc/ssh/sshd_config
|
|
57
|
+ else
|
|
58
|
+ echo 'ClientAliveInterval 60' >> /etc/ssh/sshd_config
|
|
59
|
+ fi
|
|
60
|
+ if grep -q 'ClientAliveCountMax' /etc/ssh/sshd_config; then
|
|
61
|
+ sed -i 's/ClientAliveCountMax.*/ClientAliveCountMax 3/g' /etc/ssh/sshd_config
|
|
62
|
+ else
|
|
63
|
+ echo 'ClientAliveCountMax 3' >> /etc/ssh/sshd_config
|
|
64
|
+ fi
|
|
65
|
+ if grep -q 'Ciphers' /etc/ssh/sshd_config; then
|
|
66
|
+ sed -i "s|Ciphers.*|Ciphers $SSH_CIPHERS|g" /etc/ssh/sshd_config
|
|
67
|
+ else
|
|
68
|
+ echo "Ciphers $SSH_CIPHERS" >> /etc/ssh/sshd_config
|
|
69
|
+ fi
|
|
70
|
+ if grep -q 'MACs' /etc/ssh/sshd_config; then
|
|
71
|
+ sed -i "s|MACs.*|MACs $SSH_MACS|g" /etc/ssh/sshd_config
|
|
72
|
+ else
|
|
73
|
+ echo "MACs $SSH_MACS" >> /etc/ssh/sshd_config
|
|
74
|
+ fi
|
|
75
|
+ if grep -q 'KexAlgorithms' /etc/ssh/sshd_config; then
|
|
76
|
+ sed -i "s|KexAlgorithms.*|KexAlgorithms $SSH_KEX|g" /etc/ssh/sshd_config
|
|
77
|
+ else
|
|
78
|
+ echo "KexAlgorithms $SSH_KEX" >> /etc/ssh/sshd_config
|
|
79
|
+ fi
|
80
|
80
|
|
81
|
|
- apt-get -y install fail2ban
|
|
81
|
+ apt-get -y install fail2ban
|
82
|
82
|
|
83
|
|
- function_check configure_firewall_for_ssh
|
84
|
|
- configure_firewall_for_ssh
|
85
|
|
- echo 'configure_ssh' >> $COMPLETION_FILE
|
|
83
|
+ function_check configure_firewall_for_ssh
|
|
84
|
+ configure_firewall_for_ssh
|
|
85
|
+ echo 'configure_ssh' >> $COMPLETION_FILE
|
86
|
86
|
}
|
87
|
87
|
|
88
|
88
|
# see https://stribika.github.io/2015/01/04/secure-secure-shell.html
|
89
|
89
|
function ssh_remove_small_moduli {
|
90
|
|
- awk '$5 > 2000' /etc/ssh/moduli > ~/moduli
|
91
|
|
- mv ~/moduli /etc/ssh/moduli
|
|
90
|
+ awk '$5 > 2000' /etc/ssh/moduli > ~/moduli
|
|
91
|
+ mv ~/moduli /etc/ssh/moduli
|
92
|
92
|
}
|
93
|
93
|
|
94
|
94
|
function configure_ssh_client {
|
95
|
|
- if grep -Fxq "configure_ssh_client" $COMPLETION_FILE; then
|
96
|
|
- return
|
97
|
|
- fi
|
98
|
|
- #sed -i 's/# PasswordAuthentication.*/ PasswordAuthentication no/g' /etc/ssh/ssh_config
|
99
|
|
- #sed -i 's/# ChallengeResponseAuthentication.*/ ChallengeResponseAuthentication no/g' /etc/ssh/ssh_config
|
100
|
|
- sed -i "s/# HostKeyAlgorithms.*/ HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
|
101
|
|
- sed -i "s/# Ciphers.*/ Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
|
102
|
|
- sed -i "s/# MACs.*/ MACs $SSH_MACS/g" /etc/ssh/ssh_config
|
103
|
|
- if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
|
104
|
|
- echo " HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> /etc/ssh/ssh_config
|
105
|
|
- fi
|
106
|
|
- sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
|
107
|
|
- if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
|
108
|
|
- echo " Ciphers $SSH_CIPHERS" >> /etc/ssh/ssh_config
|
109
|
|
- fi
|
110
|
|
- sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
|
111
|
|
- if ! grep -q "MACs " /etc/ssh/ssh_config; then
|
112
|
|
- echo " MACs $SSH_MACS" >> /etc/ssh/ssh_config
|
113
|
|
- fi
|
|
95
|
+ if grep -Fxq "configure_ssh_client" $COMPLETION_FILE; then
|
|
96
|
+ return
|
|
97
|
+ fi
|
|
98
|
+ #sed -i 's/# PasswordAuthentication.*/ PasswordAuthentication no/g' /etc/ssh/ssh_config
|
|
99
|
+ #sed -i 's/# ChallengeResponseAuthentication.*/ ChallengeResponseAuthentication no/g' /etc/ssh/ssh_config
|
|
100
|
+ sed -i "s/# HostKeyAlgorithms.*/ HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
|
|
101
|
+ sed -i "s/# Ciphers.*/ Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
|
|
102
|
+ sed -i "s/# MACs.*/ MACs $SSH_MACS/g" /etc/ssh/ssh_config
|
|
103
|
+ if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
|
|
104
|
+ echo " HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> /etc/ssh/ssh_config
|
|
105
|
+ fi
|
|
106
|
+ sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
|
|
107
|
+ if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
|
|
108
|
+ echo " Ciphers $SSH_CIPHERS" >> /etc/ssh/ssh_config
|
|
109
|
+ fi
|
|
110
|
+ sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
|
|
111
|
+ if ! grep -q "MACs " /etc/ssh/ssh_config; then
|
|
112
|
+ echo " MACs $SSH_MACS" >> /etc/ssh/ssh_config
|
|
113
|
+ fi
|
114
|
114
|
|
115
|
|
- # Create ssh keys
|
116
|
|
- if [ ! -f ~/.ssh/id_ed25519 ]; then
|
117
|
|
- ssh-keygen -t ed25519 -o -a 100
|
118
|
|
- fi
|
119
|
|
- if [ ! -f ~/.ssh/id_rsa ]; then
|
120
|
|
- ssh-keygen -t rsa -b 4096 -o -a 100
|
121
|
|
- fi
|
|
115
|
+ # Create ssh keys
|
|
116
|
+ if [ ! -f ~/.ssh/id_ed25519 ]; then
|
|
117
|
+ ssh-keygen -t ed25519 -o -a 100
|
|
118
|
+ fi
|
|
119
|
+ if [ ! -f ~/.ssh/id_rsa ]; then
|
|
120
|
+ ssh-keygen -t rsa -b 4096 -o -a 100
|
|
121
|
+ fi
|
122
|
122
|
|
123
|
|
- function_check ssh_remove_small_moduli
|
124
|
|
- ssh_remove_small_moduli
|
125
|
|
- echo 'configure_ssh_client' >> $COMPLETION_FILE
|
|
123
|
+ function_check ssh_remove_small_moduli
|
|
124
|
+ ssh_remove_small_moduli
|
|
125
|
+ echo 'configure_ssh_client' >> $COMPLETION_FILE
|
126
|
126
|
}
|
127
|
127
|
|
128
|
128
|
function regenerate_ssh_keys {
|
129
|
|
- if grep -Fxq "regenerate_ssh_keys" $COMPLETION_FILE; then
|
130
|
|
- return
|
131
|
|
- fi
|
132
|
|
- rm -f /etc/ssh/ssh_host_*
|
133
|
|
- dpkg-reconfigure openssh-server
|
|
129
|
+ if grep -Fxq "regenerate_ssh_keys" $COMPLETION_FILE; then
|
|
130
|
+ return
|
|
131
|
+ fi
|
|
132
|
+ rm -f /etc/ssh/ssh_host_*
|
|
133
|
+ dpkg-reconfigure openssh-server
|
134
|
134
|
|
135
|
|
- function_check ssh_remove_small_moduli
|
136
|
|
- ssh_remove_small_moduli
|
|
135
|
+ function_check ssh_remove_small_moduli
|
|
136
|
+ ssh_remove_small_moduli
|
137
|
137
|
|
138
|
138
|
systemctl restart ssh
|
139
|
|
- echo 'regenerate_ssh_keys' >> $COMPLETION_FILE
|
|
139
|
+ echo 'regenerate_ssh_keys' >> $COMPLETION_FILE
|
140
|
140
|
}
|
141
|
141
|
|
142
|
142
|
# NOTE: deliberately no exit 0
|