Overview
This document outlines several valuable modifications you can implement on your server to enhance SSH security. It is highly recommended to restrict and properly configure Secure Shell (SSH) access to secure your server effectively.
Control SSH Access
Grant SSH access only to users who genuinely require it. To revoke a user's SSH access, utilize WHM’s Manage Shell Access interface (WHM » Home » Account Functions » Manage Shell Access).
For users who need SSH access but only require access to files in their home directory, assigning a jailed shell environment is advisable. More information on jailed shells can be found in our VirtFS - Jailed Shell documentation.
Configure an SSH Legal Message
Your system can display a legal message (message of the day, or motd
) to users logging into your server via SSH. To set this message, edit the /etc/motd
file using your preferred text editor and save your changes. For instance, a technical analyst might use the following message:
|
|
Implement SSH Keys for Authentication
Disabling password authentication for SSH on your server can compel users to log in exclusively with SSH keys. To achieve this, follow these steps:
- Utilize WHM’s Manage root’s SSH Keys interface (WHM » Home » Security Center » Manage root’s SSH Keys) to generate and download a key for the root user.
- Use WHM’s SSH Password Authorization Tweak interface (WHM » Home » Security Center » SSH Password Authorization Tweak) to disable password authentication for SSH.
Enhance SSH Security Settings
The /etc/ssh/sshd_config
file contains the configuration settings for your server’s SSH service. We recommend modifying the following settings to bolster security:
Port
— This defines the port number on which thesshd
daemon listens for incoming connections. The maximum acceptable value is49151
.Note: It is advisable to use a privileged port between
1
and1023
that is not currently in use by another service. Only theroot
user can bind to ports in this range. Unprivileged ports (1024
and greater) can be used by any user.Protocol
— Specifies the SSH protocol version your server uses. We recommend setting this value to2
.ListenAddress
— The IP address where thesshd
daemon will listen for connections. This IP address must be owned by your server. It is strongly recommended to avoid using your main shared IP address for this value. Instead, consider creating a custom DNS entry (e.g.,ssh.example.com
) with an A record pointing to the new SSH IP address.PermitRootLogin
— This option determines whether direct SSH login for theroot
user is permitted. We strongly advise setting this value tono
.
Edit the sshd_config file
To configure the /etc/ssh/sshd_config
file and enhance your server’s security, follow these steps:
- Log in to your server as the
root
user via SSH. If directroot
logins are not allowed, log in as your wheel user and use thesu
command to become theroot
user. - Back up the
sshd_config
file using the following command:cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak`date +%F`
- Open the
/etc/ssh/sshd_config
file with a text editor. - To modify a parameter, uncomment the relevant line by removing the number-sign character (
#
) and then change its value. For example, to change the SSH port from its default to456
, modify the line to resemble:Port 456
After configuring SSH, run the /scripts/restart_sshd
script or the service sshd restart
command to restart the SSH daemon.
Once SSH has restarted, log out and then log back into your server using the user, IP address, and port number specified in the modified sshd_config
file.
Warning: If you inadvertently misconfigure your SSH configuration file, access the following link in your web browser (replace
example.com
with your server’s hostname or main IP address):https://example.com:2087/scripts2/doautofixer?autofix=safesshrestart
This script will temporarily set up an additional SSH configuration file for port
22
, allowing you to access, edit, and correct the original SSH configuration file. If port22
is already in use by another service, the script will configure an additional SSH configuration file for port23
.
Example sshd_config File
Warning: Do not copy and use the example file below on your server, as it will likely disrupt your SSH service configuration. This file is provided for reference only.
|
|