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
6165AcceptEnv LANG LC_*
6266
@@ -66,19 +70,77 @@ AllowAgentForwarding no
6670# prevent TCP ports from being forwarded over SSH tunnels
6771AllowTcpForwarding 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
74120ChallengeResponseAuthentication 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
77137Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
78138HostKeyAlgorithms rsa-sha2-512,rsa-sha2-256,ssh-ed25519
79139KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256
80140MACs 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
83145ClientAliveCountMax 2
84146
@@ -89,44 +151,22 @@ ClientAliveInterval 300
89151# compression before encryption might cause security issues
90152Compression 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
97155IgnoreRhosts 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
106161MaxSessions 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
125168Protocol 2
126169
127- # enable pubkey authentication
128- PubkeyAuthentication yes
129-
130170# override default of no subsystems
131171Subsystem sftp /usr/libexec/openssh/sftp-server
132172
@@ -135,12 +175,4 @@ TCPKeepAlive no
135175
136176# disable reverse DNS lookups
137177UseDNS 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```
0 commit comments