{"id":3448,"date":"2020-09-09T09:00:46","date_gmt":"2020-09-09T01:00:46","guid":{"rendered":"https:\/\/www.casbay.com\/blog\/?p=3448"},"modified":"2022-09-22T18:39:17","modified_gmt":"2022-09-22T10:39:17","slug":"how-to-configure-a-secure-ssh-based","status":"publish","type":"post","link":"https:\/\/www.casbay.com\/blog\/tips-sharing\/how-to-configure-a-secure-ssh-based","title":{"rendered":"How to Configure a Secure SSH-Based"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"3448\" class=\"elementor elementor-3448\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-72bdc877 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"72bdc877\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-6fb08062\" data-id=\"6fb08062\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-4516c0a0 elementor-widget elementor-widget-text-editor\" data-id=\"4516c0a0\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<h3><strong>Introduction <\/strong><\/h3><p>SSH is a remote connection method, whether or not it is a VPS. It is versatile and multi-platform, allows you to almost monitor your computer, as you were, and it has many useful features.<br \/><br \/>Yet protection is an important focus in the modern world of IT, so I will share some details about how to ensure access to your ssh. You&#8217;ll build a couple of keys: public and private. Privacy is your secure key for protecting, safeguarding and sharing with no one. It&#8217;s used as a special user to mark you. Public is a key to be delivered to remote servers or services.<\/p><h3><strong>Accessions<\/strong><\/h3><p>You&#8217;ll need:<br \/>1) CentOS 7.4 <a href=\"https:\/\/www.casbay.com\/asia-vps-hosting\">VPS server<\/a><br \/>2) Basic knowledge how to edit files in Linux systems<br \/>3) Linux or Windows host machine, from which you access the VPS server.<\/p><h2><strong>Generating A SSH Key Pair on Your Host Machines<\/strong><\/h2><p>If your system, from which you access VPS, is Linux ( Fedora 25 system was used, as a typical home\/workplace Linux system):<br \/>1) run ssh-keygen and follow on-screen instructions<br \/>&#8220;ssh-keygen&#8221;<\/p><figure id=\"attachment_3998\" aria-describedby=\"caption-attachment-3998\" style=\"width: 605px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-3998 size-full\" src=\"https:\/\/www.casbay.com\/blog\/wp-content\/uploads\/2021\/02\/SSH-command-ssh-keygen.png\" alt=\"SSH-command ssh-keygen\" width=\"605\" height=\"347\" \/><figcaption id=\"caption-attachment-3998\" class=\"wp-caption-text\">SSH command &#8220;ssh-keygen&#8221;<\/figcaption><\/figure><p>You can enter a specific location of storage (you can leave this as it is). You will also be asked for a password to secure the key by ssh-keygen. Although passwordless, as it is sometimes useful for different setups (automatic systems without user input), the password should be protected from your key and your key will only not allow an attacker to access the VPS-server even if your key pair is compromised.<br \/>Remember password. When you forget it, you can&#8217;t restore your key control.<\/p><figure id=\"attachment_4005\" aria-describedby=\"caption-attachment-4005\" style=\"width: 605px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-4005 size-full\" src=\"https:\/\/www.casbay.com\/blog\/wp-content\/uploads\/2021\/02\/SSH-remember-password.png\" alt=\"SSH-password \" width=\"605\" height=\"61\" \/><figcaption id=\"caption-attachment-4005\" class=\"wp-caption-text\">Must Remember Password<\/figcaption><\/figure><p>2) Backup your keys on a secure, safe storage<br \/>3) run cat \/home\/vpsuser\/.ssh\/id_rsa.pub ( replace path with the one, you have actually used ) and copy the key.<\/p><p>4) You need to put a copied key as a new string into<br \/>`\/root\/.ssh\/authorized_keys`<br \/>on your VPS server. It should look like this<\/p><figure id=\"attachment_3997\" aria-describedby=\"caption-attachment-3997\" style=\"width: 606px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-3997 size-full\" src=\"https:\/\/www.casbay.com\/blog\/wp-content\/uploads\/2021\/02\/SSH-command-copy-key-as-a-new-string-on-VPS-server.png\" alt=\"SSH-command copy key as a new string on VPS server\" width=\"606\" height=\"163\" \/><figcaption id=\"caption-attachment-3997\" class=\"wp-caption-text\">SSH-command copy key as a new string on VPS server<\/figcaption><\/figure><p>Notice that each key starts as a separate string.<br \/>5) To connect from linux machine to your VPS server through ssh, you just need to run<br \/>&#8220;ssh -i \/home\/vpsuser\/.ssh\/id_rsa.pub root@&#8221;<\/p><figure id=\"attachment_3999\" aria-describedby=\"caption-attachment-3999\" style=\"width: 605px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3999 size-full\" src=\"https:\/\/www.casbay.com\/blog\/wp-content\/uploads\/2021\/02\/SSH-command-to-connect-linux-machine.png\" alt=\"Connect from linux machine to VPS server through SSH\" width=\"605\" height=\"70\" \/><figcaption id=\"caption-attachment-3999\" class=\"wp-caption-text\">Connect from linux machine to VPS server through SSH<\/figcaption><\/figure><p>If your system, from which you access VPS, is Windows ( Windows 10 was used, as a typical home\/workplace Windows system): 1) Run puttygen tool, that comes out of the box with a putty installation.<\/p><figure id=\"attachment_4001\" aria-describedby=\"caption-attachment-4001\" style=\"width: 480px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4001 size-full\" src=\"https:\/\/www.casbay.com\/blog\/wp-content\/uploads\/2021\/02\/SSH-PuTTY-Key-Generator-tool.png\" alt=\"SSH-PuTTY Key Generator tool\" width=\"480\" height=\"469\" \/><figcaption id=\"caption-attachment-4001\" class=\"wp-caption-text\">PuTTY Key Generator tool<\/figcaption><\/figure><p>Press &#8220;generate&#8221; and it will ask you to move mouse on the empty area to generate random data, and will provide you an ssh key pair.<\/p><figure id=\"attachment_4002\" aria-describedby=\"caption-attachment-4002\" style=\"width: 478px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4002 size-full\" src=\"https:\/\/www.casbay.com\/blog\/wp-content\/uploads\/2021\/02\/SSH-PuTTY-tools-key-in-info.png\" alt=\"SSH-PuTTY tools key in info\" width=\"478\" height=\"473\" \/><figcaption id=\"caption-attachment-4002\" class=\"wp-caption-text\">SSH key pair<\/figcaption><\/figure><p>2.1) Enter password to &#8220;Key passphraze&#8221; and confirmation fields. Remember the password.<br \/>2.2) Copy the contents of the &#8220;public key for pasting into Openssh authorized_keys file:&#8221;<br \/>2.3) Save public and private key to a secure, safe storage<\/p><p>3) Copy&#8217;s the contents of the &#8220;public key for pasting into Openssh authorized_keys file:&#8221; windows in puttygen<br \/>4) Go back to your VPS server. We need to add the public part of the key pair, we have just created to the list of authorized keys. Put a copied key as a new string into<br \/>\/root\/.ssh\/authorized_keys<br \/>On your VPS server. It should look like this<\/p><figure id=\"attachment_3996\" aria-describedby=\"caption-attachment-3996\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3996 size-large\" src=\"https:\/\/www.casbay.com\/blog\/wp-content\/uploads\/2021\/02\/SSH-add-public-part-of-the-key-pair.png\" alt=\"SSH-add the public part of the key pair on VPS server\" width=\"1024\" height=\"270\" \/><figcaption id=\"caption-attachment-3996\" class=\"wp-caption-text\">add the public part of the key pair on VPS server<\/figcaption><\/figure><p>Notice that each key starts as a separate string.<br \/>5) Test connection to your VPS server<br \/>5.1) Open putty and go to Connection &#8211; SSH &#8211; Auth in the left panel.<br \/>5.2) Open you private key file by pressing Browse near the Private key for authentication field.<\/p><figure id=\"attachment_4003\" aria-describedby=\"caption-attachment-4003\" style=\"width: 446px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4003 size-full\" src=\"https:\/\/www.casbay.com\/blog\/wp-content\/uploads\/2021\/02\/SSH-PuTTY-private-key-file.png\" alt=\"SSH-PuTTY private key file\" width=\"446\" height=\"443\" \/><figcaption id=\"caption-attachment-4003\" class=\"wp-caption-text\">Open Private Key File for authentication field<\/figcaption><\/figure><p>5.3) Go back to Session in the left panel of putty, enter your server hostname or ip with a login name ( optional, as putty will prompt for it anyway ) and press Open.<\/p><figure id=\"attachment_4000\" aria-describedby=\"caption-attachment-4000\" style=\"width: 451px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4000 size-full\" src=\"https:\/\/www.casbay.com\/blog\/wp-content\/uploads\/2021\/02\/SSH-PuTTY-Configuration-host-name.png\" alt=\"SSH-PuTTY Configuration-hostname or IP\" width=\"451\" height=\"443\" \/><figcaption id=\"caption-attachment-4000\" class=\"wp-caption-text\">Enter your server Hostname or IP<\/figcaption><\/figure><p>5.4) Putty will prompt for key password at it&#8217;s screen, and if entered correctly, forward you to your VPS server console<\/p><figure id=\"attachment_4004\" aria-describedby=\"caption-attachment-4004\" style=\"width: 660px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4004 size-full\" src=\"https:\/\/www.casbay.com\/blog\/wp-content\/uploads\/2021\/02\/SSH-PuTTY-prompt-for-key-password.png\" alt=\"PuTTY-prompt for key password\" width=\"660\" height=\"417\" \/><figcaption id=\"caption-attachment-4004\" class=\"wp-caption-text\">PuTTY-prompt for key password<\/figcaption><\/figure><p>\u00a0<\/p><h3><strong>Securing Your SSH Server<\/strong><\/h3><p>Using Linux and Windows, you can now easily connect to your VPS server. You should currently disable access to your machine with a password, so any attempts to bruteforce are useless. Without an authorized ssh key your system will just not accept an incoming ssh connection. Open on your VPS server<br \/>&#8220;\/etc\/sshd\/sshd_config&#8221;<br \/>and change &#8220;PasswordAuthentication yes&#8221; string to &#8220;PasswordAuthentication no&#8221; restart sshd daemon<br \/>&#8220;systemctl restart sshd&#8221;<br \/>and check that it has no problems<br \/>&#8220;systemstl status sshd&#8221;<\/p><figure id=\"attachment_4006\" aria-describedby=\"caption-attachment-4006\" style=\"width: 724px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4006 size-full\" src=\"https:\/\/www.casbay.com\/blog\/wp-content\/uploads\/2021\/02\/SSH-securing-your-SSH-Server.png\" alt=\"Securing Your SSH Server\" width=\"724\" height=\"144\" \/><figcaption id=\"caption-attachment-4006\" class=\"wp-caption-text\">Securing Your SSH Server<\/figcaption><\/figure><p>\u00a0<\/p><h3><strong>Conclusion<\/strong><\/h3><p>Securing your link to your ssh-key pair and preventing a password login are a fundamental measure of security. It protects your server against a lot of attacks based on alphabetical password and bruteforce searches. In conclusion, secure at least basic steps for your VPS server to allow you to sleep better.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Introduction SSH is a remote connection method, whether or not it is a VPS. It is versatile and multi-platform, allows [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":33286,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":"","_wpscppro_custom_social_share_image":0},"categories":[89],"tags":[102],"_links":{"self":[{"href":"https:\/\/www.casbay.com\/blog\/wp-json\/wp\/v2\/posts\/3448"}],"collection":[{"href":"https:\/\/www.casbay.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.casbay.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.casbay.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.casbay.com\/blog\/wp-json\/wp\/v2\/comments?post=3448"}],"version-history":[{"count":18,"href":"https:\/\/www.casbay.com\/blog\/wp-json\/wp\/v2\/posts\/3448\/revisions"}],"predecessor-version":[{"id":34768,"href":"https:\/\/www.casbay.com\/blog\/wp-json\/wp\/v2\/posts\/3448\/revisions\/34768"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.casbay.com\/blog\/wp-json\/wp\/v2\/media\/33286"}],"wp:attachment":[{"href":"https:\/\/www.casbay.com\/blog\/wp-json\/wp\/v2\/media?parent=3448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.casbay.com\/blog\/wp-json\/wp\/v2\/categories?post=3448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.casbay.com\/blog\/wp-json\/wp\/v2\/tags?post=3448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}