{"id":58781,"date":"2020-12-15T09:13:22","date_gmt":"2020-12-15T15:13:22","guid":{"rendered":"https:\/\/blog.cpanel.com\/?p=58781"},"modified":"2020-12-15T09:13:22","modified_gmt":"2020-12-15T15:13:22","slug":"linux-security-enhancement-with-cpanel-whm","status":"publish","type":"post","link":"https:\/\/devel.www.cpanel.net\/blog\/tips-and-tricks\/linux-security-enhancement-with-cpanel-whm\/","title":{"rendered":"Linux Security Enhancement with cPanel & WHM\u00ae"},"content":{"rendered":"\n
The internet is a hostile environment, and your web hosting servers face innumerable threats from bad actors who want to steal data and exploit server resources. CentOS is a stable and secure foundation, but it is not invulnerable. Configuration mistakes, software vulnerabilities, and poor Linux security practices can open the door to bad actors and malicious bots.<\/p>\n\n\n\n
cPanel & WHM includes many Linux security tools that help server administrators to build a secure hosting environment. In this article, we\u2019re going to look at four techniques that leverage cPanel and WHM to enhance Linux server security.<\/p>\n\n\n\n
We\u2019re focusing on server-level security, so you will need access to your server\u2019s root account, both in WHM and on the command line via SSH<\/a>.<\/p>\n\n\n\n SSH (Secure Shell) is an encrypted network protocol that keeps authentication credentials and data safe when you connect to your server\u2019s shell. The server runs an SSH service, and a client on your local device connects to it. Communication between them is encrypted so eavesdroppers can\u2019t see sensitive data traveling over the network.<\/p>\n\n\n\n The SSH service traditionally listens for connections on port 22, so bots target that port with brute-force attacks that attempt to guess a valid username and password. Even if users choose long and hard-to-guess passwords\u2014which is not always the case\u2014brute-force attacks can generate a vast number of failed login attempts that waste server resources.<\/p>\n\n\n\n Changing the port number confuses unsophisticated bots. If they can\u2019t find the port, they can\u2019t attempt to log in. A Linux server has 65535 (27<\/sup>) available ports. You should avoid 0\u20131023\u2014the so-called well-known ports, including SSH\u2019s 22\u2014but you are free to choose between 1024\u201365535.<\/p>\n\n\n\n Before you begin, be sure to configure your firewall<\/a> to allow connections on the new port. Otherwise, it will block SSH connections, and you won\u2019t be able to log in.<\/p>\n\n\n\n Log in as root with SSH and open the \/etc\/ssh\/sshd_config file in your preferred text editor.<\/p>\n\n\n\n Find the line that reads:<\/p>\n\n\n\n Delete the pound sign at the beginning of the line and change the 22 to your new port.<\/p>\n\n\n\n Save and close the SSH configuration file. Finally, restart the SSH service:<\/p>\n\n\n\n <\/p>\n\n\n\n Changing the SSH port reduces brute-force log-in attempts, but it won\u2019t stop a motivated attacker. Another way to improve SSH security avoids passwords in favor of SSH keys. SSH keys are more secure and, if password logins are disabled, they make successful brute-force attacks impossible.<\/p>\n\n\n\n SSH keys have a public and a private component. The public key is stored on the server, and the private key is stored on the client machine. Only users with the private key can log in to the relevant account. We\u2019ll focus on securing the root account with SSH keys, but site administrators and resellers can use a similar approach in cPanel<\/a>.<\/p>\n\n\n\n First, we\u2019ll generate new SSH keys for root in WHM. Log in to WHM and navigate to Manage Root\u2019s SSH Keys<\/em>.<\/p>\n\n\n\nHow To Change the SSH Port in cPanel<\/strong><\/h2>\n\n\n\n
nano \/etc\/ssh\/sshd_config<\/code><\/pre>\n\n\n\n
#Port 22<\/code><\/pre>\n\n\n\n
Port 32356<\/code><\/pre>\n\n\n\n
\/scripts\/restart_ssh<\/code><\/pre>\n\n\n\n
Be sure to take note of the port number you chose. Next time you log in to SSH, specify the port in your SSH command:<\/p>\n\n\n\nssh -p 32356 user@example.com<\/code><\/pre>\n\n\n\n
How To Use SSH Keys with the Root Account<\/strong><\/h2>\n\n\n\n