securing vps

When you buy VPS(Virtual Private Server) with root login credential there are some steps you can perform in order to secure the VPS.

1). UPDATE THE SYSTEM.

yum update -y
yum upgrade -y

2).CREATING A NORMAL USER ACCOUNT.

To create a user and grant it administrative privileges on a server running CentOS or Fedora, follow these steps:

  • Log in to the server using SSH
  • At the command prompt, type the following command. Replace username with the name of the user that you want to add:
useradd username
  • Type the following command, replacing username with the name of the user that you create
passwd username
  • To grant administrative privileges to the user, type the following command:
visudo
  • Add the following line to the file. Replace username with the name of the user that you created
username ALL=(ALL) ALL

Now the user can run commands as the root user by prefixing the command with sudo.Ex:- sudo ls /root

3).DISABLING SSH LOGIN FOR ROOT

  • Log in to the server as root using SSH.
  • Open the /etc/ssh/sshd_config file
vi /etc/ssh/sshd_config
  • Locate the following line:
PermitRootLogin yes
  • Modify the line as follows:
PermitRootLogin no
  • Add the following line. Replace username with the name of the user you created in the previous procedure:
AllowUsers username
  • Save the changes to the /etc/ssh/sshd_config file, and
  • Restart the SSH service using the appropriate command for your Linux distribution:
service sshd restart

4).CHANGING THE SSH PORT

  • Login to system
  • Type following
sudo vi /etc/ssh/sshd_config
  • Locate the following line:
# Port 22
  • Remove # and change 22 to your desired port number.
  • Restart the sshd service by running the following command:
service sshd restart

 

Leave a Reply

Your email address will not be published. Required fields are marked *