How to Configure and Secure the SSH Server (sshd) with Examples

watch 2m, 56s
views 2

14:05, 22.05.2026

Article Content
arrow

  • How Configuration Files Interact
  • Typical Settings for Personal SSH Use
  • Common SSH Config Adjustments for Organizations
  • Encryption Policy Settings
  • Enabling Detailed Logging
  • Setting the Path for AuthorizedKeysFile
  • Controlling Root Access
  • Displaying a Login Banner
  • Managing Port Forwarding Settings
  • Using Certificate-Based Authentication
  • sshd_config Syntax and Structure Explained

Secure Shell (SSH) is a cornerstone of remote server management. Its server component, sshd, offers powerful configuration options for both casual users and enterprise administrators. This guide walks through how to configure and secure sshd, with practical examples to help you understand and implement best practices.

How Configuration Files Interact

The primary configuration file for the SSH daemon is /etc/ssh/sshd_config. This file determines how the server behaves when it accepts SSH connections.

In contrast, client settings live in /etc/ssh/ssh_config or the user's ~/.ssh/config file. However, sshd_config is where administrators control authentication methods, access rules, and session behavior.

When the SSH daemon starts or reloads, it reads sshd_config in top-down order. If a directive is repeated, the last valid occurrence usually takes effect. After making changes, run:

sudo systemctl restart sshd

Or on some systems:

sudo service ssh restart

To test the config before restarting:

sshd -t

Typical Settings for Personal SSH Use

If you're managing a personal VPS or home lab, you can improve security and convenience with a few simple adjustments:

Port 2222 
PermitRootLogin no 
PasswordAuthentication no 
AllowUsers alice

These settings change the default SSH port, disable root logins, require key-based authentication, and restrict access to specific users. Always back up the original file before making changes.

Common SSH Config Adjustments for Organizations

In enterprise environments, SSH configuration must balance usability, compliance, and security. Below are essential settings that organizations often adjust in sshd_config.

Encryption Policy Settings

Set strong, modern encryption algorithms to protect data in transit. Use the Ciphers, MACs, and KexAlgorithms directives:

Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com 
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com 
KexAlgorithms curve25519-sha256,ecdh-sha2-nistp521

These settings remove outdated algorithms and enforce cryptographic best practices.

Enabling Detailed Logging

For auditing and debugging purposes, increase logging verbosity:

LogLevel VERBOSE

This provides more granular information about user activity and authentication attempts, which is useful for security monitoring.

Setting the Path for AuthorizedKeysFile

To centralize or customize where public keys are read from:

AuthorizedKeysFile /etc/ssh/authorized_keys/%u

This example stores each user’s public key under a shared directory, replacing %u with the username.

Controlling Root Access

Root login should be tightly controlled or disabled entirely:

PermitRootLogin prohibit-password

This allows root login only via key-based authentication. To disable root access altogether:

PermitRootLogin no

Displaying a Login Banner

To meet compliance standards or display a legal warning, configure a login banner:

Banner /etc/issue.net

Populate /etc/issue.net with the desired message, such as:

Unauthorized access to this system is prohibited. 
All activity is monitored and logged.

Managing Port Forwarding Settings

Restrict or enable port forwarding depending on internal policy:

AllowTcpForwarding no 
PermitTunnel no 
X11Forwarding no

For users who need secure tunneling, these can be selectively enabled.

Using Certificate-Based Authentication

For environments managing large numbers of users, SSH certificates offer scalable access control. Generate a CA key and sign user public keys:

ssh-keygen -s ca_key -I user_id user_key.pub
In sshd_config, specify the trusted CA:
TrustedUserCAKeys /etc/ssh/ca.pub

This allows any key signed by the specified CA to authenticate, simplifying user management.

sshd_config Syntax and Structure Explained

The syntax of sshd_config is simple: one directive per line, followed by its value(s). Comments begin with #. 

# This is a comment 
Port 22 
PermitRootLogin no

Directives are case-insensitive but should follow conventional formatting for readability. Common mistakes include:

  • Trailing spaces
  • Invalid parameter values
  • Repeating conflicting directives

To apply changes:

sudo systemctl reload sshd

Or use sshd -t before restarting to ensure the syntax is valid.

Share

Was this article helpful to you?

VPS popular offers

-10%

CPU
CPU
2 Xeon Cores
RAM
RAM
512 MB
Space
Space
10 GB SSD
Bandwidth
Bandwidth
Unlimited
KVM-SSD 512 Linux

5.2 /mo

/mo

Billed annually

-10%

CPU
CPU
4 Epyc Cores
RAM
RAM
4 GB
Space
Space
50 GB NVMe
Bandwidth
Bandwidth
Unlimited
Keitaro KVM 4096
OS
CentOS
Software
Software
Keitaro

18.1 /mo

/mo

Billed annually

-10%

CPU
CPU
4 Xeon Cores
RAM
RAM
2 GB
Space
Space
75 GB SSD
Bandwidth
Bandwidth
Unlimited
wKVM-SSD 2048 Windows

10.23 /mo

/mo

Billed annually

-29.4%

CPU
CPU
4 Xeon Cores
RAM
RAM
2 GB
Space
Space
30 GB SSD
Bandwidth
Bandwidth
2 TB
KVM-SSD 2048 Metered Linux

17 /mo

/mo

Billed annually

-10%

CPU
CPU
6 Xeon Cores
RAM
RAM
16 GB
Space
Space
150 GB SSD
Bandwidth
Bandwidth
Unlimited
KVM-SSD 16384 Linux

49.99 /mo

/mo

Billed annually

-10%

CPU
CPU
4 Xeon Cores
RAM
RAM
2 GB
Space
Space
30 GB SSD
Bandwidth
Bandwidth
Unlimited
KVM-SSD 2048 Linux

8.3 /mo

/mo

Billed annually

-15.3%

CPU
CPU
4 Xeon Cores
RAM
RAM
2 GB
Space
Space
75 GB SSD
Bandwidth
Bandwidth
40 Mbps
DDoS Protected SSD-wKVM 2048 Windows

54 /mo

/mo

Billed annually

-20.4%

CPU
CPU
2 Xeon Cores
RAM
RAM
2 GB
Space
Space
30 GB SSD
Bandwidth
Bandwidth
300 GB
KVM-SSD 2048 HK Linux

18 /mo

/mo

Billed annually

-10%

CPU
CPU
4 Xeon Cores
RAM
RAM
4 GB
Space
Space
100 GB SSD
Bandwidth
Bandwidth
Unlimited
MT5 KVM 4096 Windows

19.99 /mo

/mo

Billed annually

-10%

CPU
CPU
4 Xeon Cores
RAM
RAM
8 GB
Space
Space
100 GB SSD
Bandwidth
Bandwidth
Unlimited
10Ge-KVM-SSD 8192 Linux

115.5 /mo

/mo

Billed annually

Other articles on this topic

cookie

Accept cookies & privacy policy?

We use cookies to ensure that we give you the best experience on our website. If you continue without changing your settings, we'll assume that you are happy to receive all cookies on the HostZealot website.