How to Secure and Harden Cloud VM (Ubuntu & CentOS)? | |
---|---|
Theresa Chavez Offline Topics: 1 Replies: 2 Joined: 04/06/2020 |
Securing OS is as important as your website, web applications, online business. You may be spending on security plugin, WAF, cloud-based security to protect your site (Layer 7) but leaving OS unhardened can be dangerous. Let’s get into a practical guide to secure Ubuntu and CentOS VM.
1. Changing SSH Default PortBy default, SSH daemon listens on port number 22. This means if anyone finds your IP can attempt to connect to your server. They may not be able to get into the server if you have secured with a complex password. However, they can launch brute force attacks to disturb the server operation. The best thing is to change the SSH port to something else so even though if someone knows the IP, they can’t attempt to connect using default SSH port. Changing the SSH port in Ubuntu/CentOS is very easy.
Look for line which has
Now, you or anyone won’t be able to connect to your server using SSH default port. Instead, you can use the new port to connect. If using SSH client or Terminal on MAC then you can use
Easy, isn’t it? 2. Protecting from Brute Force AttacksOne of the common mechanisms used by a hacker to take control of your online business is by initiating brute force attacks against the server and web platform like WordPress, Joomla, etc. This can be dangerous if not taken seriously. There are two popular programs you can use to protect Linux from brute force. SSH GuardSSHGuard monitors the running services from the system log files and blocks repeated bad login attempts. Initially, it was meant for SSH login protection, but now it supports many others.
You can get SSHGuard installed with the following commands. Ubuntu:
CentOS:
Fail2BanFail2Ban is another popular program to protect SSH. Fail2Ban automatically updates the iptables rule if a failed login attempt reaches the defined threshold. To install Fail2Ban in Ubuntu:
and to install in CentOS:
SSH Guard and Fail2Ban should be sufficient to protect SSH login. However, if you need to explore more then, you may refer to the following. 3. Disable Password-based AuthenticationIf you log in to your server from one or two computers, then you can use SSH key based authentication. However, if you have multiple users and often log in from multiple public computers then, it might be troublesome to exchange key every time. So based on the situation, if you opt to disable password-based authentication, you can do it as following. Note: this assumes you have already set up SSH key exchange.
PasswordAuthentication no
4. Protecting from DDoS AttacksDDoS (Distributed Denial of Service) can happen at any layer, and this is the last thing you want as a business owner. Finding the origin IP is possible, and as a best practice, you shouldn’t be exposing your server IP to the public Internet. There are multiple ways to hide the “Origin IP” to prevent the DDoS on your cloud/VPS server. Use a load balancer (LB) – implement an Internet-facing load balancer, so server IP is not exposed to the Internet. There are many load balancers you can choose from – Google Cloud LB, AWS ELB, Linode Nodebalancer, DO LB, etc. Use a CDN (Content Delivery Network) – CDN is one of the great ways to improve website performance and security. When you implement CDN, you configure DNS A record with the anycast IP address provided by the CDN provider. By doing this, you are advertising CDN provider IP for your domain and origin is not exposed. There is many CDN provider to accelerate the website performance, DDoS protection, WAF & many other features. So pick the CDN provider who provider performance & security both. Tweak the Kernel settings & iptables – you can leverage iptables to block suspicious requests, non-SYN, bogus TCP flag, private subnet and more. Along with iptables, you may also configure the kernel settings. Javapipe has explained it well with the instructions so that I won’t duplicate it here. Use a firewall – If you afford a hardware-based firewall then excellent otherwise you may want to use a software-based firewall that leverages iptables to protect the incoming network connection to the VM. There are many, but one of the most popular ones is UFW (Uncomplicated Firewall) for Ubuntu and FirewallD for CentOS. 5. Regular BackupBackup is your friend! When nothing works then the backup will rescue you. Things can go wrong, but what if you don’t have the necessary backup to restore? Most of the cloud or VPS providers offer backup at a little extra charge and one should always consider. Check with your VPS provider how to enable backup service. I know Linode and DO charge 20% of droplet pricing for the backup. If you are on Google Compute Engine or AWS, then schedule a daily snapshot. Having a backup will quickly allow you to restore the entire VM, so you are back in business. Or with the help of a snapshot, you can clone the VM. 6. Regular UpdateKeeping your VM OS up-to-date is one of the essential tasks to ensure your server is not exposed to any latest security vulnerabilities. In Ubuntu, you can use In CentOS, you can use 7. Don’t leave opened portsIn another word, allow the needed ports only. Keeping unwanted open ports like an inviting attacker to take advantage. If you are just hosting your website on your VM then most likely you need either port 80 (HTTP) or 443 (HTTPS). And if you are using VPS then apply basic iptables ruleset as explained in Linode guide. The above should help you in hardening and secure your server for better protection from online threats. |
06/06/2020 11:51:52 |
|
Kevin Young Offline Topics: 4 Replies: 30 Moderator |
That you for posting, we've doubled your RAM for free. |
02/07/2020 21:44:57 |
|
Theresa Chavez Offline Topics: 1 Replies: 2 Joined: 04/06/2020 |
Thanks |
03/07/2020 09:32:26 |