Deny SSH access by ip address on cpanel

There are many ways available to secure SSH on cPanel Server. We can deny SSH access to all other ip address except from our ISP ips.  In order to allow our ip address and deny all other ips use the following method.

From within your WHM head to Security Center >> Host Access Control.
Here we can add in some rules to control who can access sshd.

Example

Daemon        Access List                  Action                     Comments

sshd            xxx.xxx.xx.xxxx              allow                     working ISPs

sshd              ALL                       deny                  Deny all other ips

 

Limit SSH per IP and user
You can limit ssh using /etc/hosts.deny and /etc/hosts.allow. We can use instead of this will deal with the AllowUsers feature in SSH that will limit access per user, and if desired per ip.

To enable this edit /etc/ssh/sshd_config (default location on centos servers, this may be different for you).

At the very bottom you can add

AllowUsers root

This will limit access to only user root. All other login attempts will fail. This will stop the chance of a brute force attach getting into your server as any user but root.

You can also add an IP address

AllowUsers [email protected] [email protected]

This above setting will allow user root from xxx.11x.2x.1xx user admin from 1x.1xx.2x.1xx

Restart SSHD service

You must restart SSH for the changes to take place. On centos servers that is /etc/init.d/sshd restart type service sshd restart in console/terminal or go to Restart Services >> SSH Server (OpenSSH).

Was this article helpful?

Related Articles

Leave A Comment?