How to secure SSH in Centos

Status
Not open for further replies.

Bharat

Active Member
2,001
2010
840
320
When you first begin to approach your newly installed server, there are a few early steps you should take to make it more secure from hackers. The first tasks can include setting up a new user, providing them with the proper privileges, and configuring SSH.

Step One — Login via Root

fT0za96.png


Step Two — Change Your Password For Root

cXrX1aV.png


CentOS is very cautious about the passwords it allows. After you type your password, you may see a BAD PASSWORD notice. You can either set a more complex password or ignore the message .

Step Three — Creating a New User For Root privileges

First, create your user; you can choose any name for your user.

Code:
adduser username

For example here I’ve suggested secure as a user .

nqfLAKx.png


Second, create a new user password :

Code:
passwd secure

cLWDkzy.png


Step Four — Assigning Root Privileges

As of yet, only root has all of the administrative capabilities. We are going to give the new user the root privileges.

Let’s go ahead and edit the sudo configuration. This can be done through the default editor, which in CentOS is called ‘vi’

Code:
/usr/sbin/visudo

TNk3P9e.png


Find the section called user privilege specification and add the similar line below it .

To began typing in vi, press “a”.

Code:
secure    ALL=(ALL)       ALL

KMJB8OV.png


Then to save and exit press escape , then press ":w" to write the file and to quit press ":q" .

Step Five — Configuring SSH To Disable Root Login

Open the configuration file

Code:
sudo vi /etc/ssh/sshd_config

It will then look something like this :

tnQ6sK3.png


Find the following sections and change the information where applicable:

Port 750 ( <-- you can change it to any port , it will disable 22 as default port for accessing ssh)
Protocol 2
PermitRootLogin no ( <-- This will disable direct root login )

It will then look something like this :-

Et3UUiK.png


Once the above is done , just add the below line to the bottom of the document, replacing secure with your username:

Code:
AllowUsers secure

Save and Exit

Step Six — Reload and Done!

Reload SSH, and it will implement the new ports and settings.

Code:
service sshd restart

4J406xv.png


Finally you can login to your SSH using the user secure with port 750 .

1UVgUKz.png


gCvORR3.png


Few more steps that can be done to get the thing more secured :- http://www.wjunction.com/1820961-post5.htm

I hope this will help and few users to secure the SSH from unauthorized people .
 
Last edited:
7 comments
Its been a great help with this post , i just tried the same steps and worked very well . Great share :) I am sure it will be helpful for many . :D
 
good tutorial, to add you can also restrict ssh from specific IP (good if you have static IP ) or to an IP range
Code:
sudo vi /etc/ssh/sshd_config
OR with nano editor ( easy for newbie)
Code:
nano /etc/ssh/sshd_config
and add at the end of file

For single user with static IP
Code:
AllowUsers root@192.168.0.1
For entire subnet to login as root (ie . 192.168.0.1-192.168.0.254)
Code:
AllowUsers root@192.168.0.?
obviously change 192.168.0.1 to your IP address which you wants to allow access.
 
good tutorial, to add you can also restrict ssh from specific IP (good if you have static IP ) or to an IP range
Code:
sudo vi /etc/ssh/sshd_config
OR with nano editor ( easy for newbie)
Code:
nano /etc/ssh/sshd_config
and add at the end of file

For single user with static IP
Code:
AllowUsers root@192.168.0.1
For entire subnet to login as root (ie . 192.168.0.1-192.168.0.254)
Code:
AllowUsers root@192.168.0.?
obviously change 192.168.0.1 to your IP address which you wants to allow access.

Thanks , appreciated ! Added to my main post as well .
 
Status
Not open for further replies.
Back
Top