Skip to content

Commit 35efc7c

Browse files
authored
Create sshd_config_passwordless
1 parent d96f974 commit 35efc7c

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed

Linux/sshd_config_passwordless

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
##REFS:
2+
# https://linux.die.net/man/5/sshd_config
3+
# https://github.com/k4yt3x/sshd_config/blob/master/sshd_config
4+
# /usr/share/openssh/sshd_config
5+
6+
Include /etc/ssh/sshd_config.d/*.conf
7+
8+
#-------------------------------------------------------#
9+
########## Address ##########
10+
Port 22
11+
#AddressFamily any
12+
#ListenAddress 0.0.0.0
13+
#ListenAddress ::
14+
#-------------------------------------------------------#
15+
16+
#-------------------------------------------------------#
17+
########## Features ##########
18+
#Accept locale-related environment variables
19+
AcceptEnv LANG LC_*
20+
#Disallow ssh-agent forwarding to prevent lateral movement
21+
AllowAgentForwarding no
22+
#Prevent TCP ports from being forwarded over SSH tunnels
23+
# **please be aware that disabling TCP forwarding does not prevent port forwarding**
24+
# any user with an interactive login shell can spin up his/her own instance of sshd
25+
AllowTcpForwarding no
26+
#Prevent StreamLocal (Unix-domain socket) forwarding
27+
AllowStreamLocalForwarding no
28+
#Disallow remote hosts from connecting to forwarded ports
29+
# i.e. forwarded ports are forced to bind to 127.0.0.1 instead of 0.0.0.0
30+
GatewayPorts no
31+
#Prevent tun device forwarding
32+
PermitTunnel no
33+
#Specifies whether sshd(8) should print /etc/motd when a user logs in interactively. [Default: yes]
34+
PrintMotd yes
35+
#Specifies whether X11 forwarding is permitted. [Default: no]
36+
X11Forwarding yes
37+
#-------------------------------------------------------#
38+
39+
#-------------------------------------------------------#
40+
########## Authentication ##########
41+
#Permit only the specified users to login
42+
#AllowUsers k4yt3x
43+
#Permit only users within the specified groups to login
44+
#AllowGroups k4yt3x
45+
#Specifies the file that contains the public keys that can be used for user authentication. AuthorizedKeysFile may contain tokens of the form %T which are substituted during connection setup. The following tokens are defined: %% is replaced by a literal '%', %h is replaced by the home directory of the user being authenticated, and %u is replaced by the username of that user. After expansion, AuthorizedKeysFile is taken to be an absolute path or one relative to the user's home directory. The default is ''.ssh/authorized_keys''.
46+
# chmod 700 $HOME/.ssh
47+
# chmod 600 $HOME/.ssh/authorized_keys /etc/ssh/authorized_keys
48+
AuthorizedKeysFile %h/.ssh/authorized_keys /etc/ssh/authorized_keys
49+
#Uncomment the following options to permit only pubkey authentication
50+
#Be aware that this will disable password authentication
51+
# - AuthenticationMethods: permitted authentication methods
52+
# - PasswordAuthentication: set to no to disable password authentication
53+
# - UsePAM: set to no to disable all PAM authentication, also disables PasswordAuthentication when set to no
54+
AuthenticationMethods publickey
55+
PasswordAuthentication no
56+
#PAM authentication enabled to make password authentication available
57+
#Remove this if password authentication is not needed
58+
UsePAM no
59+
#Challenge-response authentication backend it not configured by default
60+
# therefore, it is set to "no" by default to avoid the use of an unconfigured backend
61+
ChallengeResponseAuthentication no
62+
#Set maximum authentication retries to prevent brute force attacks
63+
MaxAuthTries 3
64+
#Disallow connecting using empty passwords
65+
PermitEmptyPasswords no
66+
#Prevent root from being logged in via SSH
67+
PermitRootLogin no
68+
#Enable pubkey authentication
69+
PubkeyAuthentication yes
70+
#-------------------------------------------------------#
71+
72+
#-------------------------------------------------------#
73+
########## Cryptography ##########
74+
#Explicitly define cryptography algorithms to avoid the use of weak algorithms
75+
# AES-CTR and Chacha20-Poly1305 modes have been removed to mitigate the Terrapin attack
76+
# https://terrapin-attack.com/
77+
78+
#HostKeyAlgorithms rsa-sha2-512,rsa-sha2-256,ssh-ed25519
79+
80+
#---KEYS---#
81+
##Only use host keys with secure HostKeyAlgorithms
82+
#https://www.ssh.com/academy/ssh/keygen#sec-Choosing-an-Algorithm-and-Key-Size
83+
##dsa - an old US government Digital Signature Algorithm. It is based on the difficulty of computing discrete logarithms. A key size of 1024 would normally be used with it. DSA in its original form is no longer recommended.
84+
#HostKey /etc/ssh/ssh_host_dsa_key
85+
##rsa - an old algorithm based on the difficulty of factoring large numbers. A key size of at least 2048 bits is recommended for RSA; 4096 bits is better. RSA is getting old and significant advances are being made in factoring. Choosing a different algorithm may be advisable. It is quite possible the RSA algorithm will become practically breakable in the foreseeable future. All SSH clients support this algorithm.
86+
HostKey /etc/ssh/ssh_host_rsa_key
87+
##ecdsa - a new Digital Signature Algorithm standarized by the US government, using elliptic curves. This is probably a good algorithm for current applications. Only three key sizes are supported: 256, 384, and 521 (sic!) bits. We would recommend always using it with 521 bits, since the keys are still small and probably more secure than the smaller keys (even though they should be safe as well). Most SSH clients now support this algorithm.
88+
HostKey /etc/ssh/ssh_host_ecdsa_key
89+
##ed25519 - this is a new algorithm added in OpenSSH. Support for it in clients is not yet universal. Thus its use in general purpose applications may not yet be advisable.
90+
HostKey /etc/ssh/ssh_host_ed25519_key
91+
# short moduli should be deactivated before enabling the use of diffie-hellman-group-exchange-sha256
92+
# see this link for more details: https://github.com/k4yt3x/sshd_config#deactivating-short-diffie-hellman-moduli
93+
# AES-CTR and Chacha20-Poly1305 modes have been removed to mitigate the Terrapin attack
94+
# https://terrapin-attack.com/
95+
# ecdh-sha2-nistp* algorithms have been removed due to concerns around NIST P-curves' design
96+
# https://github.com/jtesta/ssh-audit/issues/213#issuecomment-1774204745
97+
#KexAlgorithms [email protected],curve25519-sha256,[email protected],diffie-hellman-group18-sha512,diffie-hellman-group16-sha512
98+
#-------------------------------------------------------#
99+
100+
#-------------------------------------------------------#
101+
########## Connection Preferences ##########
102+
# Debian-based distributions only
103+
# hide the Debian banner to prevent information disclosure
104+
# (e.g., `SSH-2.0-OpenSSH_8.4p1 Debian-5+deb11u3`)
105+
#DebianBanner no
106+
#Number of client alive messages sent without client responding [Default: 3]
107+
ClientAliveCountMax 6
108+
#Send a keepalive message to the client when the session has been idle for 300 seconds
109+
#Disconnects if no response [Default: 0]
110+
ClientAliveInterval 0
111+
#Compression before encryption might cause security issues
112+
Compression yes
113+
# prevent SSH trust relationships from allowing lateral movements
114+
IgnoreRhosts yes
115+
# log verbosely for additional information
116+
#LogLevel VERBOSE
117+
#Allow a maximum of two multiplexed sessions over a single TCP connection [Default: 10]
118+
MaxSessions 20
119+
#Enforce SSH server to only use SSH protocol version 2
120+
# SSHv1 contains security issues and should be avoided at all costs
121+
# SSHv1 is disabled by default after OpenSSH 7.0, but this option is
122+
# specified anyways to ensure this configuration file's compatibility
123+
# with older versions of OpenSSH server
124+
Protocol 2
125+
#Override default of no subsystems [Only one entry is permitted]
126+
# path to the sftp-server binary depends on your distribution
127+
#Subsystem sftp /usr/lib/openssh/sftp-server
128+
#Subsystem sftp /usr/libexec/openssh/sftp-server
129+
Subsystem sftp internal-sftp
130+
#let ClientAliveInterval handle keepalive
131+
#Specifies whether the system should send TCP keepalive messages to the other side. If they are sent, death of the connection or crash of one of the machines will be properly noticed. However, this means that connections will die if the route is down temporarily, and some people find it annoying. On the other hand, if TCP keepalives are not sent, sessions may hang indefinitely on the server, leaving ''ghost'' users and consuming server resources.
132+
#The default is ''yes'' (to send TCP keepalive messages), and the server will notice if the network goes down or the client host crashes. This avoids infinitely hanging sessions.
133+
#To disable TCP keepalive messages, the value should be set to ''no''.
134+
TCPKeepAlive yes
135+
#Specifies whether sshd(8) should look up the remote host name and check that the resolved host name for the remote IP address maps back to the very same IP address. The default is ''yes''.
136+
#Set no to disable reverse DNS lookups
137+
UseDNS no
138+
#-------------------------------------------------------#
139+
140+
#-------------------------------------------------------#
141+
########## Logging ##########
142+
# sudo less "/var/log/auth.log"
143+
# sudo less "/var/log/syslog"
144+
# sudo less "/var/log/fail2ban.log"
145+
#Gives the verbosity level that is used when logging messages from sshd(8). The possible values are: QUIET, FATAL, ERROR, INFO, VERBOSE, DEBUG, DEBUG1, DEBUG2, and DEBUG3. The default is INFO. DEBUG and DEBUG1 are equivalent. DEBUG2 and DEBUG3 each specify higher levels of debugging output. Logging with a DEBUG level violates the privacy of users and is not recommended.
146+
LogLevel VERBOSE
147+
#Gives the facility code that is used when logging messages from sshd(8). The possible values are: DAEMON, USER, AUTH, AUTHPRIV, LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7. The default is AUTH.
148+
SyslogFacility AUTH
149+
#-------------------------------------------------------#

0 commit comments

Comments
 (0)