{"id":95,"date":"2013-05-18T21:35:17","date_gmt":"2013-05-18T21:35:17","guid":{"rendered":"http:\/\/blog.shineservers.com\/?p=95"},"modified":"2013-05-18T21:35:17","modified_gmt":"2013-05-18T21:35:17","slug":"how-to-secure-ssh-in-centos","status":"publish","type":"post","link":"https:\/\/www.shineservers.com\/2013\/05\/18\/how-to-secure-ssh-in-centos\/","title":{"rendered":"How to secure SSH in Centos"},"content":{"rendered":"<p>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.<\/p>\n<p><b>Step One \u2014 Login via Root\u00a0<\/b><\/p>\n<p><img decoding=\"async\" id=\"ncode_imageresizer_container_1\" alt=\"\" src=\"http:\/\/i.imgur.com\/fT0za96.png\" width=\"700\" height=\"69\" border=\"0\" \/><\/p>\n<p><b>Step Two \u2014 Change Your Password For Root<\/b><\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" id=\"ncode_imageresizer_container_2\" alt=\"\" src=\"http:\/\/i.imgur.com\/cXrX1aV.png\" width=\"700\" height=\"127\" border=\"0\" \/><\/p>\n<p>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 .<\/p>\n<p><b>Step Three \u2014 Creating a New User For Root privileges<\/b><\/p>\n<p>First, create your user; you can choose any name for your user.<\/p>\n<div>\n<pre dir=\"ltr\">[code]adduser username[\/code]<\/pre>\n<\/div>\n<p>For example here I\u2019ve suggested\u00a0<b>secure<\/b>\u00a0as a user .<\/p>\n<p><img decoding=\"async\" id=\"ncode_imageresizer_container_3\" alt=\"\" src=\"http:\/\/i.imgur.com\/nqfLAKx.png\" width=\"700\" height=\"62\" border=\"0\" \/><\/p>\n<p><b>Second, create a new user password :<\/b><\/p>\n<div>\n<pre dir=\"ltr\">[code]passwd secure[\/code]<\/pre>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" id=\"ncode_imageresizer_container_4\" alt=\"\" src=\"http:\/\/i.imgur.com\/cLWDkzy.png\" width=\"700\" height=\"123\" border=\"0\" \/><\/p>\n<p><b>Step Four \u2014 Assigning Root Privileges<\/b><\/p>\n<p>As of yet, only root has all of the administrative capabilities. We are going to give the new user the root privileges.<\/p>\n<p>Let\u2019s go ahead and edit the sudo configuration. This can be done through the default editor, which in CentOS is called \u2018vi\u2019<\/p>\n<div>\n<pre dir=\"ltr\">[code]\/usr\/sbin\/visudo[\/code]<\/pre>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" id=\"ncode_imageresizer_container_5\" alt=\"\" src=\"http:\/\/i.imgur.com\/TNk3P9e.png\" width=\"700\" height=\"43\" border=\"0\" \/><\/p>\n<p>Find the section called user privilege specification and add the similar line below it .<\/p>\n<p>To began typing in vi, press \u201ca\u201d.<\/p>\n<div>\n<pre dir=\"ltr\">[code]secure    ALL=(ALL)       ALL[\/code]<\/pre>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" id=\"ncode_imageresizer_container_6\" alt=\"\" src=\"http:\/\/i.imgur.com\/KMJB8OV.png\" width=\"700\" height=\"58\" border=\"0\" \/><\/p>\n<p>Then to save and exit press escape , then press &#8220;:w&#8221; to write the file and to quit press &#8220;:q&#8221; .<\/p>\n<p><b>Step Five \u2014 Configuring SSH To Disable Root Login<\/b><\/p>\n<p>Open the configuration file<\/p>\n<div>\n<pre dir=\"ltr\">[code]sudo vi \/etc\/ssh\/sshd_config[\/code]<\/pre>\n<\/div>\n<p>It will then look something like this :<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" id=\"ncode_imageresizer_container_7\" alt=\"\" src=\"http:\/\/i.imgur.com\/tnQ6sK3.png\" width=\"700\" height=\"541\" border=\"0\" \/><\/p>\n<p>Find the following sections and change the information where applicable:<\/p>\n<p><b>Port 750\u00a0<\/b>( &lt;&#8211; you can change it to any port , it will disable 22 as default port for accessing ssh)<br \/>\n<b>Protocol 2<\/b><br \/>\n<b>PermitRootLogin no<\/b>\u00a0( &lt;&#8211; This will disable direct root login )<\/p>\n<p>It will then look something like this :-<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/i.imgur.com\/Et3UUiK.png\" border=\"0\" \/><\/p>\n<p>Once the above is done , just add the below line to the bottom of the document, replacing secure with your username:<\/p>\n<div>\n<pre dir=\"ltr\">[code]AllowUsers secure[\/code]<\/pre>\n<\/div>\n<p>Save and Exit<\/p>\n<p><b>Step Six \u2014 Reload and Done!<\/b><\/p>\n<p>Reload SSH, and it will implement the new ports and settings.<\/p>\n<div>\n<div><\/div>\n<pre dir=\"ltr\">[code]service sshd restart[\/code]<\/pre>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" id=\"ncode_imageresizer_container_8\" alt=\"\" src=\"http:\/\/i.imgur.com\/4J406xv.png\" width=\"700\" height=\"87\" border=\"0\" \/><\/p>\n<p>Finally you can login to your SSH using the user secure with port 750 .<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/i.imgur.com\/1UVgUKz.png\" border=\"0\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" id=\"ncode_imageresizer_container_9\" alt=\"\" src=\"http:\/\/i.imgur.com\/gCvORR3.png\" width=\"700\" height=\"66\" border=\"0\" \/><\/p>\n<p>I hope this will help and few users to secure the SSH from unauthorized people .<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 \u2014 Login via Root\u00a0 Step Two \u2014 Change [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[60],"tags":[66],"class_list":["post-95","post","type-post","status-publish","format-standard","hentry","category-linux","tag-secure-ssh-centos"],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/95","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/comments?post=95"}],"version-history":[{"count":0,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/95\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/media?parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/categories?post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/tags?post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}