{"id":486,"date":"2011-12-15T10:47:31","date_gmt":"2011-12-15T15:47:31","guid":{"rendered":"http:\/\/www.serverprontouniversity.com\/?p=486"},"modified":"2018-08-16T23:34:19","modified_gmt":"2018-08-17T04:34:19","slug":"support-of-the-day-ssh-keys-passwordless-login-via-ssh","status":"publish","type":"post","link":"https:\/\/www.serverpronto.com\/spu\/2011\/12\/support-of-the-day-ssh-keys-passwordless-login-via-ssh\/","title":{"rendered":"Support of the day: SSH Keys"},"content":{"rendered":"<div id=\"_mcePaste\">This week\u00e2\u20ac\u2122s tip: SSH Keys (or I do not like typing my long cryptic password everytime I need to access my server)<\/div>\n<div id=\"_mcePaste\">If you\u00e2\u20ac\u2122ve been following my other tips you might remember that ssh uses different authentication options, credentials, domain login, password, you name it, one of these is via ssh keys.<\/div>\n<p><!--more--><\/p>\n<h1>SSH Keys<\/h1>\n<div id=\"_mcePaste\">Imagine your car. You\u00e2\u20ac\u2122re used to using a key to open the door and start the engine once or twice per day. How about if you were a messenger that has to do this 40, 50, 60 times per day, it gets tiresome, wouldn\u00e2\u20ac\u2122t it be great for the car to open the door and automatically start the engine when it senses that it\u00e2\u20ac\u2122s you?<\/div>\n<div><\/div>\n<div id=\"_mcePaste\">The same principle bit different.<\/div>\n<div id=\"_mcePaste\">(Please note, that this tutorial is aimed to Linux to Linux connections, putty has a local key generator that could be technically used as the same.)<\/div>\n<div><\/div>\n<div id=\"_mcePaste\">1. Creating the keys and their folder<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">First, create the local folder, type mkdir \/home\/$USER\/.ssh (type it just like that)<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">Then the key: ssh-keygen -t dsa (anything it asks just press enter)<\/div>\n<div style=\"padding-left: 30px;\"><\/div>\n<div id=\"_mcePaste\">2. Copying the key to the remote server<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">Move to the ssh folder: cd \/home\/$USER\/.ssh<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">Copy the file: scp id_dsa.pub yourremoteuser@remoteip:.\/id_dsa.pub<\/div>\n<div style=\"padding-left: 30px;\"><\/div>\n<div id=\"_mcePaste\">3. Adding the key on the remote server<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">First, log in to the remote server via ssh as usual<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">Then add the key to the remote server\u00e2\u20ac\u2122s key list:<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">cd \/home\/remoteusername\/<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">mkdir .ssh<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">mv id_dsa.pub .ssh\/<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">cd .ssh\/<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">check if there is a file named authorized_keys, if not then create it:<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">touch authorized_keys<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">finally, add the key:<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">cat id_dsa.pub &gt;&gt; authorized_keys<\/div>\n<div style=\"padding-left: 30px;\"><\/div>\n<div id=\"_mcePaste\">4. Activating the keys used on the remote server.<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">Type: nano \/etc\/ssh\/sshd_config<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">And look for AuthorizedKeysFile and make sure that it&#8217;s uncommented (meaning that there is no # symbol before that word) and that next to it says .ssh\/authorized_keys<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">Save (Ctrl + x) and restart the ssh service.<\/div>\n<div style=\"padding-left: 30px;\"><\/div>\n<div id=\"_mcePaste\">5. Testing.<\/div>\n<div id=\"_mcePaste\" style=\"padding-left: 30px;\">Log out of the remote server and try to log in again, this time it will not ask for a password.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This week\u00e2\u20ac\u2122s tip: SSH Keys (or I do not like typing my long cryptic password everytime I need to access my server) If you\u00e2\u20ac\u2122ve been following my other tips you might remember that ssh uses different authentication options, credentials, domain login, password, you name it, one of these is via ssh keys.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64],"tags":[123,17,112,27,22,18],"class_list":["post-486","post","type-post","status-publish","format-standard","category-support-of-the-day","tag-cloud","tag-dedicated-server","tag-hosting","tag-linux","tag-server","tag-web-hosting"],"_links":{"self":[{"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/posts\/486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/comments?post=486"}],"version-history":[{"count":8,"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/posts\/486\/revisions"}],"predecessor-version":[{"id":2629,"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/posts\/486\/revisions\/2629"}],"wp:attachment":[{"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/media?parent=486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/categories?post=486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.serverpronto.com\/spu\/wp-json\/wp\/v2\/tags?post=486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}