/etc/ssh/sshd_config
The sshd_config
file is the main configuration file for the OpenSSH SSH daemon (sshd
). It controls various aspects of how sshd
operates, including authentication methods, port settings, and user permissions. This file is typically located at /etc/ssh/sshd_config
on most Linux systems.
Here is a detailed overview of common settings in /etc/ssh/sshd_config
:
Basic Configuration Options
Port:
Specifies the port number
sshd
listens on. The default is 22.Example:
ListenAddress:
Specifies the IP address
sshd
should listen on. You can specify multiple addresses.Example:
PermitRootLogin:
Controls whether the root user can log in via SSH. Options include
yes
,no
,without-password
,prohibit-password
.Example:
PasswordAuthentication:
Enables or disables password authentication. For improved security, consider using key-based authentication.
Example:
PubkeyAuthentication:
Enables or disables public key authentication.
Example:
PermitEmptyPasswords:
Allows or disallows login with empty passwords.
Example:
ChallengeResponseAuthentication:
Enables or disables challenge-response authentication (such as OTP).
Example:
UsePAM:
Specifies whether to use Pluggable Authentication Modules (PAM) for authentication.
Example:
AllowUsers:
Specifies which users are allowed to log in via SSH.
Example:
DenyUsers:
Specifies which users are denied SSH access.
Example:
AllowGroups:
Specifies which groups are allowed to log in via SSH.
Example:
DenyGroups:
Specifies which groups are denied SSH access.
Example:
X11Forwarding:
Enables or disables X11 forwarding.
Example:
AllowTcpForwarding:
Controls whether TCP forwarding is allowed.
Example:
PrintMotd:
Controls whether the message of the day (MOTD) is printed when a user logs in.
Example:
Subsystem:
Configures subsystems like
sftp
. By default, OpenSSH provides an SFTP subsystem.Example:
PermitTunnel:
Allows or disallows tunnelled sessions.
Example:
LogLevel:
Sets the verbosity of logging. Levels include
QUIET
,FATAL
,ERROR
,INFO
,VERBOSE
,DEBUG
, andDEBUG1
,DEBUG2
,DEBUG3
for more detailed debugging.Example:
Example Configuration
Here is an example of a more secure sshd_config
:
Reloading Configuration
After making changes to sshd_config
, you need to reload or restart the sshd
service to apply the changes:
Reload (to apply configuration changes without disconnecting active sessions):
Restart (to restart the
sshd
service):
Summary
The sshd_config
file is crucial for configuring how the SSH daemon operates, including security settings, authentication methods, and user permissions. Properly configuring this file helps secure SSH access and manage how users connect to the system.
Last updated