Skip to content

Commit dca0cc2

Browse files
committed
version 1.1: moved items into sections, added sandboxing option
1 parent 131fe47 commit dca0cc2

File tree

2 files changed

+129
-65
lines changed

2 files changed

+129
-65
lines changed

README.md

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# K4YT3X's Hardened OpenSSH Server Configuration
22

3-
This repository hosts my hardened version of OpenSSH server configuration file.
3+
This repository hosts my hardened version of OpenSSH server (6.7+) configuration file.
44

55
**Please review the configuration file carefully before applying it.** You are responsible for actions done to your own system.
66

@@ -43,8 +43,10 @@ You may want to use the [ssh-audit](https://github.com/jtesta/ssh-audit) script
4343
# Name: K4YT3X Hardened OpenSSH Configuration
4444
# Author: K4YT3X
4545
# Date Created: October 5, 2020
46-
# Last Updated: October 5, 2020
47-
# Version: 1.0
46+
# Last Updated: October 6, 2020
47+
# Version: 1.1
48+
49+
########## Binding ##########
4850

4951
# SSH server listening address and port
5052
#Port 22
@@ -57,6 +59,8 @@ You may want to use the [ssh-audit](https://github.com/jtesta/ssh-audit) script
5759
# only listen to IPv6
5860
#AddressFamily inet6
5961

62+
########## Features ##########
63+
6064
# accept locale-related environment variables
6165
AcceptEnv LANG LC_*
6266

@@ -66,19 +70,77 @@ AllowAgentForwarding no
6670
# prevent TCP ports from being forwarded over SSH tunnels
6771
AllowTcpForwarding no
6872

73+
# prevent StreamLocal (Unix-domain socket) forwarding
74+
AllowStreamLocalForwarding no
75+
76+
# disables all forwarding features
77+
# overrides all other forwarding switches
78+
DisableForwarding yes
79+
80+
# disallow remote hosts from connecting to forwarded ports
81+
# i.e. forwarded ports are forced to bind to 127.0.0.1 instad of 0.0.0.0
82+
GatewayPorts no
83+
84+
# prevent tun device forwarding
85+
PermitTunnel no
86+
87+
# suppress MOTD
88+
PrintMotd no
89+
90+
# use kernel sandbox mechanisms where possible in unprivileged processes
91+
# systrace on OpenBSD, Seccomp on Linux, seatbelt on MacOSX/Darwin, rlimit elsewhere
92+
UsePrivilegeSeparation sandbox
93+
94+
# disable X11 forwarding since it is not necessary
95+
X11Forwarding no
96+
97+
########## Authentication ##########
98+
6999
# permit only the specified users to login
70100
#AllowUsers k4yt3x
71101

102+
# permit only users within the specified groups to login
103+
#AllowGroups k4yt3x
104+
105+
# uncomment the following options to permit only pubkey authentication
106+
# be aware that this will disable password authentication
107+
# - AuthenticationMethods: permitted authentication methods
108+
# - PasswordAuthentication: set to no to disable password authentication
109+
# - UsePAM: set to no to disable all PAM authentication, also disables PasswordAuthentication when set to no
110+
#AuthenticationMethods publickey
111+
#PasswordAuthentication no
112+
#UsePAM no
113+
114+
# PAM authentication enabled to make password authentication available
115+
# remove this if password authentication is not needed
116+
UsePAM yes
117+
72118
# challenge-response authentication backend it not configured by default
73119
# therefore, it is set to "no" by default to avoid the use of an unconfigured backend
74120
ChallengeResponseAuthentication no
75121

122+
# set maximum authenticaion retries to prevent brute force attacks
123+
MaxAuthTries 3
124+
125+
# disallow connecting using empty passwords
126+
PermitEmptyPasswords no
127+
128+
# prevent root from being logged in via SSH
129+
PermitRootLogin no
130+
131+
# enable pubkey authentication
132+
PubkeyAuthentication yes
133+
134+
########## Cryptography ##########
135+
76136
# explicitly define cryptography algorithms to avoid the use of weak algorithms
77137
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
78138
HostKeyAlgorithms rsa-sha2-512,rsa-sha2-256,ssh-ed25519
79139
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256
80140
MACs umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com
81141

142+
########## Connection Preferences ##########
143+
82144
# number of client alive messages sent without client responding
83145
ClientAliveCountMax 2
84146

@@ -89,44 +151,22 @@ ClientAliveInterval 300
89151
# compression before encryption might cause security issues
90152
Compression no
91153

92-
# disallow remote hosts from connecting to forwarded ports
93-
# i.e. forwarded ports are forced to bind to 127.0.0.1 instad of 0.0.0.0
94-
GatewayPorts no
95-
96154
# prevent SSH trust relationships from allowing lateral movements
97155
IgnoreRhosts yes
98156

99157
# log verbosely for addtional information
100158
#LogLevel VERBOSE
101159

102-
# set maximum authenticaion retries to prevent brute force attacks
103-
MaxAuthTries 3
104-
105160
# allow a maximum of two multiplexed sessions over a single TCP connection
106161
MaxSessions 2
107162

108-
# disable password authentication
109-
#PasswordAuthentication no
110-
111-
# disallow connecting using empty passwords
112-
PermitEmptyPasswords no
113-
114-
# prevent root from being logged in via SSH
115-
PermitRootLogin no
116-
117-
# suppress MOTD
118-
PrintMotd no
119-
120163
# enforce SSH server to only use SSH protocol version 2
121164
# SSHv1 contains security issues and should be avoided at all costs
122165
# SSHv1 is disabled by default after OpenSSH 7.0, but this option is
123166
# specified anyways to ensure this configuration file's compatibility
124167
# with older versions of OpenSSH server
125168
Protocol 2
126169

127-
# enable pubkey authentication
128-
PubkeyAuthentication yes
129-
130170
# override default of no subsystems
131171
Subsystem sftp /usr/libexec/openssh/sftp-server
132172

@@ -135,12 +175,4 @@ TCPKeepAlive no
135175

136176
# disable reverse DNS lookups
137177
UseDNS no
138-
139-
# disable PAM since it is not necessary
140-
# disables PasswordAuthentication
141-
#UsePAM no
142-
UsePAM yes
143-
144-
# disable X11 forwarding since it is not necessary
145-
X11Forwarding no
146178
```

sshd_config

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Name: K4YT3X Hardened OpenSSH Configuration
22
# Author: K4YT3X
33
# Date Created: October 5, 2020
4-
# Last Updated: October 5, 2020
5-
# Version: 1.0
4+
# Last Updated: October 6, 2020
5+
# Version: 1.1
6+
7+
########## Binding ##########
68

79
# SSH server listening address and port
810
#Port 22
@@ -15,6 +17,8 @@
1517
# only listen to IPv6
1618
#AddressFamily inet6
1719

20+
########## Features ##########
21+
1822
# accept locale-related environment variables
1923
AcceptEnv LANG LC_*
2024

@@ -24,19 +28,77 @@ AllowAgentForwarding no
2428
# prevent TCP ports from being forwarded over SSH tunnels
2529
AllowTcpForwarding no
2630

31+
# prevent StreamLocal (Unix-domain socket) forwarding
32+
AllowStreamLocalForwarding no
33+
34+
# disables all forwarding features
35+
# overrides all other forwarding switches
36+
DisableForwarding yes
37+
38+
# disallow remote hosts from connecting to forwarded ports
39+
# i.e. forwarded ports are forced to bind to 127.0.0.1 instad of 0.0.0.0
40+
GatewayPorts no
41+
42+
# prevent tun device forwarding
43+
PermitTunnel no
44+
45+
# suppress MOTD
46+
PrintMotd no
47+
48+
# use kernel sandbox mechanisms where possible in unprivileged processes
49+
# systrace on OpenBSD, Seccomp on Linux, seatbelt on MacOSX/Darwin, rlimit elsewhere
50+
UsePrivilegeSeparation sandbox
51+
52+
# disable X11 forwarding since it is not necessary
53+
X11Forwarding no
54+
55+
########## Authentication ##########
56+
2757
# permit only the specified users to login
2858
#AllowUsers k4yt3x
2959

60+
# permit only users within the specified groups to login
61+
#AllowGroups k4yt3x
62+
63+
# uncomment the following options to permit only pubkey authentication
64+
# be aware that this will disable password authentication
65+
# - AuthenticationMethods: permitted authentication methods
66+
# - PasswordAuthentication: set to no to disable password authentication
67+
# - UsePAM: set to no to disable all PAM authentication, also disables PasswordAuthentication when set to no
68+
#AuthenticationMethods publickey
69+
#PasswordAuthentication no
70+
#UsePAM no
71+
72+
# PAM authentication enabled to make password authentication available
73+
# remove this if password authentication is not needed
74+
UsePAM yes
75+
3076
# challenge-response authentication backend it not configured by default
3177
# therefore, it is set to "no" by default to avoid the use of an unconfigured backend
3278
ChallengeResponseAuthentication no
3379

80+
# set maximum authenticaion retries to prevent brute force attacks
81+
MaxAuthTries 3
82+
83+
# disallow connecting using empty passwords
84+
PermitEmptyPasswords no
85+
86+
# prevent root from being logged in via SSH
87+
PermitRootLogin no
88+
89+
# enable pubkey authentication
90+
PubkeyAuthentication yes
91+
92+
########## Cryptography ##########
93+
3494
# explicitly define cryptography algorithms to avoid the use of weak algorithms
3595
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
3696
HostKeyAlgorithms rsa-sha2-512,rsa-sha2-256,ssh-ed25519
3797
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256
3898
MACs umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com
3999

100+
########## Connection Preferences ##########
101+
40102
# number of client alive messages sent without client responding
41103
ClientAliveCountMax 2
42104

@@ -47,44 +109,22 @@ ClientAliveInterval 300
47109
# compression before encryption might cause security issues
48110
Compression no
49111

50-
# disallow remote hosts from connecting to forwarded ports
51-
# i.e. forwarded ports are forced to bind to 127.0.0.1 instad of 0.0.0.0
52-
GatewayPorts no
53-
54112
# prevent SSH trust relationships from allowing lateral movements
55113
IgnoreRhosts yes
56114

57115
# log verbosely for addtional information
58116
#LogLevel VERBOSE
59117

60-
# set maximum authenticaion retries to prevent brute force attacks
61-
MaxAuthTries 3
62-
63118
# allow a maximum of two multiplexed sessions over a single TCP connection
64119
MaxSessions 2
65120

66-
# disable password authentication
67-
#PasswordAuthentication no
68-
69-
# disallow connecting using empty passwords
70-
PermitEmptyPasswords no
71-
72-
# prevent root from being logged in via SSH
73-
PermitRootLogin no
74-
75-
# suppress MOTD
76-
PrintMotd no
77-
78121
# enforce SSH server to only use SSH protocol version 2
79122
# SSHv1 contains security issues and should be avoided at all costs
80123
# SSHv1 is disabled by default after OpenSSH 7.0, but this option is
81124
# specified anyways to ensure this configuration file's compatibility
82125
# with older versions of OpenSSH server
83126
Protocol 2
84127

85-
# enable pubkey authentication
86-
PubkeyAuthentication yes
87-
88128
# override default of no subsystems
89129
Subsystem sftp /usr/libexec/openssh/sftp-server
90130

@@ -93,11 +133,3 @@ TCPKeepAlive no
93133

94134
# disable reverse DNS lookups
95135
UseDNS no
96-
97-
# disable PAM since it is not necessary
98-
# disables PasswordAuthentication
99-
#UsePAM no
100-
UsePAM yes
101-
102-
# disable X11 forwarding since it is not necessary
103-
X11Forwarding no

0 commit comments

Comments
 (0)