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:
Port22
ListenAddress:
Specifies the IP address sshd should listen on. You can specify multiple addresses.
Example:
ListenAddress0.0.0.0ListenAddress::
PermitRootLogin:
Controls whether the root user can log in via SSH. Options include yes, no, without-password, prohibit-password.
Example:
PermitRootLoginno
PasswordAuthentication:
Enables or disables password authentication. For improved security, consider using key-based authentication.
Example:
PasswordAuthenticationyes
PubkeyAuthentication:
Enables or disables public key authentication.
Example:
PubkeyAuthenticationyes
PermitEmptyPasswords:
Allows or disallows login with empty passwords.
Example:
PermitEmptyPasswordsno
ChallengeResponseAuthentication:
Enables or disables challenge-response authentication (such as OTP).
Example:
ChallengeResponseAuthenticationno
UsePAM:
Specifies whether to use Pluggable Authentication Modules (PAM) for authentication.
Example:
UsePAMyes
AllowUsers:
Specifies which users are allowed to log in via SSH.
Example:
AllowUsersuser1user2
DenyUsers:
Specifies which users are denied SSH access.
Example:
DenyUsersuser3user4
AllowGroups:
Specifies which groups are allowed to log in via SSH.
Example:
AllowGroupssshusers
DenyGroups:
Specifies which groups are denied SSH access.
Example:
DenyGroupsbadusers
X11Forwarding:
Enables or disables X11 forwarding.
Example:
X11Forwardingyes
AllowTcpForwarding:
Controls whether TCP forwarding is allowed.
Example:
AllowTcpForwardingyes
PrintMotd:
Controls whether the message of the day (MOTD) is printed when a user logs in.
Example:
PrintMotdyes
Subsystem:
Configures subsystems like sftp. By default, OpenSSH provides an SFTP subsystem.
Example:
Subsystemsftp/usr/lib/openssh/sftp-server
PermitTunnel:
Allows or disallows tunnelled sessions.
Example:
PermitTunnelno
LogLevel:
Sets the verbosity of logging. Levels include QUIET, FATAL, ERROR, INFO, VERBOSE, DEBUG, and DEBUG1, DEBUG2, DEBUG3 for more detailed debugging.
Example:
LogLevelINFO
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.