{"id":39037,"date":"2021-11-29T15:19:14","date_gmt":"2021-11-29T15:19:14","guid":{"rendered":"https:\/\/linuxiac.com\/?p=39037"},"modified":"2022-10-07T21:37:23","modified_gmt":"2022-10-07T21:37:23","slug":"ssh-login-without-password","status":"publish","type":"post","link":"https:\/\/linuxiac.com\/ssh-login-without-password\/","title":{"rendered":"How to Setup SSH Login Without Password"},"content":{"rendered":"\n<p>SSH is used for logging into servers to run the commands and programs remotely. However, sometimes you might want or even need to automatically log in to an&nbsp;SSH&nbsp;server without entering your username and password.<\/p>\n\n\n\n<p>The two most popular mechanisms to log into remote systems via SSH are <strong>password-based authentication<\/strong> and <strong>key-based authentication<\/strong>.<\/p>\n\n\n\n<p>Username and password combination is the most common authentication method for&nbsp;SSH&nbsp;and is suitable for most people. Unfortunately, there are certain security risks associated with using this method.<\/p>\n\n\n\n<p>On the other hand, if you regularly use <a href=\"https:\/\/linuxiac.com\/how-to-use-ssh-tunneling\/\">SSH to connect to remote servers<\/a>, the key-based authentication method is best for you.<\/p>\n\n\n\n<p>So, can you SSH without a password? In short, yes! Here&#8217;s how to do it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-step-1-generate-ssh-key-pair\">Step 1: Generate SSH Key Pair<\/h2>\n\n\n\n<p>You first need to generate an SSH key pair on the machine you are currently working on.<\/p>\n\n\n\n<p>If you are unsure how to do it&nbsp;I recommend following our short and easy to follow&nbsp;guide: <a href=\"https:\/\/linuxiac.com\/generate-ssh-key-pair\/\">Generate an SSH Key Pair [with Examples]<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Copy the Public Key to Remote Server<\/h2>\n\n\n\n<p><strong>To enable SSH login without a password, you need to transfer a copy of your SSH public key to the remote server.<\/strong> Therefore, you need to know your remote server&#8217;s credentials and several other details, such as <a href=\"https:\/\/linuxiac.com\/change-hostname-linux\/\">hostname<\/a>\/IP, username, password,&nbsp;and <a href=\"https:\/\/linuxiac.com\/ssh-to-port-other-than-22\/\" target=\"_blank\" rel=\"noreferrer noopener\">port number<\/a>.<\/p>\n\n\n\n<p>To transfer the public key to the remote server, we will use the <code>ssh-copy-id<\/code> command that is available in most Linux distros. The command will copy the content of public key <code>.ssh\/id_rsa.pub<\/code> to the <code>.ssh\/authorized_keys<\/code> file in the remote system.&nbsp;<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code lang=\"bash\" class=\"hljs language-css language-bash\"><span class=\"hljs-selector-tag\">ssh-copy-id<\/span> <span class=\"hljs-selector-tag\">user<\/span><span class=\"hljs-keyword\">@remote-host<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-copy-public-key.png\"><img decoding=\"async\" width=\"956\" height=\"423\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-copy-public-key.png\" alt=\"SSH Without Password - Copy Public Key to Remote Server\" class=\"wp-image-39039\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-copy-public-key.png 956w, https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-copy-public-key-360x159.png 360w, https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-copy-public-key-768x340.png 768w, https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-copy-public-key-480x212.png 480w\" sizes=\"(max-width: 956px) 100vw, 956px\" \/><\/a><\/figure>\n\n\n\n<p>You will be prompted to enter the&nbsp;remote username&nbsp;password. Once the user is authenticated, the public key will automatically be copied into the&nbsp;<code>.ssh\/authorized_keys<\/code>&nbsp;file on the remote server.<\/p>\n\n\n\n<p>On the remote server, you can verify the transfer of the public key by viewing the content of the <code>.ssh\/authorized_keys<\/code> file.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-public-key-authorized.png\"><img decoding=\"async\" width=\"886\" height=\"404\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-public-key-authorized.png\" alt=\"Remote Server authorized_keys File\" class=\"wp-image-39040\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-public-key-authorized.png 886w, https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-public-key-authorized-360x164.png 360w, https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-public-key-authorized-768x350.png 768w, https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-public-key-authorized-480x219.png 480w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/figure>\n\n\n\n<p>For more about the&nbsp;<code>ssh-copy-id<\/code>&nbsp;command in <a href=\"https:\/\/linuxiac.com\/what-is-linux-operating-system\/\">Linux<\/a>, consult its&nbsp;<a href=\"https:\/\/linux.die.net\/man\/1\/ssh-copy-id\" target=\"_blank\" rel=\"noreferrer noopener\">manual page<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: SSH Login Without Password<\/h2>\n\n\n\n<p>Now you should be able to login into the remote server without being prompted for a password. Just try to login into your server via SSH:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code lang=\"bash\" class=\"hljs language-css language-bash\"><span class=\"hljs-selector-tag\">ssh<\/span> <span class=\"hljs-selector-tag\">username<\/span><span class=\"hljs-keyword\">@remote_server<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The system should log you directly to the remote server; no password is required.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-success.png\"><img decoding=\"async\" width=\"921\" height=\"468\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-success.png\" alt=\"SSH Login Without Password - Successfully Logged In\" class=\"wp-image-39041\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-success.png 921w, https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-success-360x183.png 360w, https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-success-768x390.png 768w, https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-success-480x244.png 480w\" sizes=\"(max-width: 921px) 100vw, 921px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>That is all you need to set up an SSH login without passwords. Then, of course, you can add the same public key to multiple remote serves.<\/p>\n\n\n\n<p>Finally, it&#8217;s important to note that you can share the public key (<code>id_rsa.pub<\/code>) with anyone but <strong>never share your private key<\/strong> (<code>id_rsa<\/code>). Only the public key is copied to the server.<\/p>\n\n\n\n<p>The private key should never be copied to another machine because anyone with the private key will be able to log into any system having the matching public key.<\/p>\n\n\n\n<p>If you have any questions or feedback, feel free to leave a comment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article will show you how to set up an SSH login without passwords in a Linux operating system by using key-based authentication<\/p>\n","protected":false},"author":10,"featured_media":39038,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,4417],"tags":[4451,3374,64],"class_list":["post-39037","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-linux-knowledge","tag-passwordless-login","tag-security","tag-ssh"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6},"post_title_panel":"","has_hero_section":"default","a0390050d2b74be76b70be3690f8c9d1":"","hero_section":"type-2","hero_elements":[{"id":"custom_title","enabled":true,"heading_tag":"h1","title":"Home","__id":"FWruQWLyvzbsxt528ZWTM"},{"id":"custom_description","enabled":false,"description_visibility":{"desktop":true,"tablet":true,"mobile":false},"__id":"n3HuOeZc_toi0iK2rpMGV"},{"id":"custom_meta","enabled":true,"meta_elements":[{"id":"author","enabled":true,"label":"By","has_author_avatar":"yes","avatar_size":50,"__id":"CUbNcwIv5O3LUKraRBvS2"},{"id":"post_date","enabled":false,"label":"On","date_format_source":"default","date_format":"M j, Y","__id":"4hTxidCozri41-gvryDbz"},{"id":"updated_date","enabled":true,"label":"Updated","date_format_source":"default","date_format":"M j, Y","__id":"Px1lgjug1NswubhSYgT3d"},{"id":"categories","enabled":false,"label":"In","style":"simple","__id":"EyAWPu5xK2cXqMqCIBNvE"},{"id":"comments","enabled":true,"__id":"GajtRs8dblv3jlHuHrqGm"}],"page_meta_elements":{"joined":true,"articles_count":true,"comments":true},"__id":"MXQIyZjBZH2ANDJyxnjHQ","meta_type":"label","meta_divider":"circle"},{"id":"breadcrumbs","enabled":false,"__id":"cMjgkl0Nsu6ZTQHtEH-tI"}],"8c848f903945c502e36aeb20bc00ce3f":"","hero_alignment1":"CT_CSS_SKIP_RULE","hero_margin":40,"hero_alignment2":"center","hero_vertical_alignment":"center","d89e17ae5cba7ea823ed38774b8d95b2":"","hero_structure":"normal","af380766ff3ef17e743ed50143768c1c":"","page_title_bg_type":"custom_image","custom_hero_background":{"attachment_id":43980,"url":"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/11\/ssh-without-password-header-1024x237.png"},"page_title_image_size":"full","parallax":{"desktop":false,"tablet":false,"mobile":false},"9bcdbfe72e4f44ed1ca985088f2b6e3b":"","hero_height":"250px","pageTitleFont":{"family":"Default","variation":"Default","size":{"desktop":"2.8em","tablet":"2.8em","mobile":"2.8em","__changed":[]},"line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"pageTitleFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageMetaFont":{"family":"Default","variation":"n6","size":"12px","line-height":"1.3","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"uppercase","text-decoration":"CT_CSS_SKIP_RULE"},"pageMetaFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"page_meta_button_type_font_colors":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"page_meta_button_type_background_colors":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageExcerptFont":{"family":"Default","variation":"Default","size":"CT_CSS_SKIP_RULE","line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"pageExcerptColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"breadcrumbsFont":{"family":"Default","variation":"Default","size":"CT_CSS_SKIP_RULE","line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"breadcrumbsFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"initial":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageTitleOverlay":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"CT_CSS_SKIP_RULE"}}},"pageTitleBackground":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"var(--theme-palette-color-6)"}}},"pageTitlePadding":{"top":"50px","bottom":"50px","left":"auto","right":"auto","linked":true},"98785481dde74835df328c8ae0a52c4c":"","page_structure_type":"default","6001aab91e70eaa3c57ffee8142773f9":"","content_style_source":"inherit","content_style":"wide","a75d93d118a0406693675dbc8ca73668":"","vertical_spacing_source":"inherit","content_area_spacing":"both","background":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"CT_CSS_SKIP_RULE"}}},"content_background":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"var(--theme-palette-color-8)"}}},"content_boxed_shadow":{"inherit":false,"blur":18,"spread":-6,"v_offset":12,"h_offset":0,"inset":false,"enable":true,"color":{"color":"rgba(34, 56, 101, 0.04)"}},"boxed_content_spacing":{"desktop":{"top":"40px","bottom":"40px","left":"40px","right":"40px","linked":true},"tablet":{"top":"35px","bottom":"35px","left":"35px","right":"35px","linked":true},"mobile":{"top":"20px","bottom":"20px","left":"20px","right":"20px","linked":true}},"content_boxed_radius":{"top":"3px","bottom":"3px","left":"3px","right":"3px","linked":true},"2ee5e1c601572e109f575acd7e0558f5":"","disable_featured_image":"no","disable_post_tags":"no","disable_share_box":"no","disable_author_box":"no","disable_posts_navigation":"no","disable_subscribe_form":"no","ea94b4fa1d2c79235bf08b93559a3add":"","disable_related_posts":"no","disable_header":"no","disable_footer":"no","82e216b48a9f66c599cc96cce25e3901":"","header_footer_scripts_panel":"","header_scripts":"","7b735bd15bbd02490526e9241fe109bc":"","header_after_body_scripts":"","226a01ced96e4152e38d366601aa8cee":"","footer_scripts":""},"_links":{"self":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts\/39037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/comments?post=39037"}],"version-history":[{"count":0,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts\/39037\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/media\/39038"}],"wp:attachment":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/media?parent=39037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/categories?post=39037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/tags?post=39037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}