SSH service can be secured in various ways like changing the SSH port, changing the ssh protocol, ssh ListenAddress, disable root login with the PermitRootLogin parameter, allowing ssh access to specific users, restricting SSH access to specific IPs etc. These steps will make sure SSH service on your server is secure.
Edit the SSHD configuration and make the changes listed below:
vi /etc/ssh/sshd_config
1) Set the default SSH port 22 to a higher value, by changing the ‘Port’ directive
Port 2233
2) To make SSH work on a secure protocol, set the ‘Protocol’ directive as
Protocol 2
3) Bind SSHD service to a specific IP of the server, which you can achieve by replacing ‘#ListenAddress’ directive to
ListenAddress xx.xx.xx.xx
where, xx.xx.xx.xx is the additional IP of the server and the only one which will allow you to SSH into the server.
4) To disable root access, set ‘PermitRootLogin’ directive to ‘no’
PermitRootLogin no
Make sure you add an alternate SSH user on the server who have privileges to gain root access before disabling this option.
5) To allow SSH access to specific users, add the “AllowUsers” directive at the end of the configuration
AllowUsers user1 user2
This will allow SSH access to users user1 and user2. You need to allow SSH access to the user who is allowed to gain root access incase root access is disabled.
Save the file and restart the sshd service
service sshd restart
6) Using the TCP wrappers i.e. hosts.allow and hosts.deny, you can restrict SSH access to specific IPs i.e. edit /etc/hosts.allow and add the following
sshd : yourlocalip: allow
sshd : all : deny
“yourlocalip” is the one assigned by your ISP. It will restrict SSH access to your local IP only.
Comments are closed.