{"id":10283,"date":"2010-01-22T17:56:00","date_gmt":"2010-01-22T17:56:00","guid":{"rendered":"https:\/\/aidanfinn.com\/?p=10283"},"modified":"2010-01-22T17:56:00","modified_gmt":"2010-01-22T17:56:00","slug":"setting-up-public-key-based-ssh-access-to-sles","status":"publish","type":"post","link":"https:\/\/aidanfinn.com\/?p=10283","title":{"rendered":"Setting Up Public Key Based SSH Access To SLES"},"content":{"rendered":"<p>I needed to set up key based, rather than password based, access to SUSE Linux Enterprise Server.&#160; It\u2019s more secure because it uses a public\/private key pair rather than a password.&#160; The user\u2019s private key is stored on the client.&#160; The private key for the user is stored on the Linux machines.&#160; When they connect using an SSH client there is no need to enter a password.&#160; You can optionally (and it\u2019s recommended) store a passphrase with the private key so that it cannot be used without knowing the private key.<\/p>\n<p>The solutions starts at the client.&#160; I normally used Putty but I couldn\u2019t get it to work properly with this type of solution.&#160; Instead I turned to <a href=\"http:\/\/en.poderosa.org\" target=\"_blank\">Poderosa<\/a>.&#160; Using it I create a public and private key pair.&#160; From there I saved the public key in OpenSSH format and the private key.<\/p>\n<p>Save the private key somewhere safe, e.g. a backed up location on your PC or on your home drive on a file server.&#160; Make sure the location is secure.<\/p>\n<p>Now you need to copy the text of the public key.&#160; Note that it is a single line.&#160; Log into the SLES machine and browse to your home directory.&#160; For example:<\/p>\n<ul>\n<li>For root browse to ~\/.ssh<\/li>\n<li>For any other user browse to \/home\/&lt;username&gt;\/.ssh<\/li>\n<\/ul>\n<p>Use a text editor (like vi) to create a file called authorized_keys in that home directory.&#160; Copy the text from your private key and paste it into the file.&#160; Save it.<\/p>\n<p>You now need to enable SSH to allow logons using keys.&#160; The configuration for SSH is stored in a text file: \/etc\/ssh\/sshd_config.&#160; Edit that and you\u2019ll have a few entries to modify.&#160; We\u2019ll start by allowing public keys to be used for authentication.&#160; This is done by setting PubkeyAuthentication to \u201cyes\u201d.&#160; I had to remove the # (comment\/remark) symbol from the start of the line.<\/p>\n<p align=\"center\">PubkeyAuthentication yes<\/p>\n<p>I restarted the SSH daemon or service by running rcsshd restart.&#160; That\u2019s required to load the new settings for authentication.&#160; <\/p>\n<p>I configured the SSH client to log in as my user to this server with my private copy of the key.&#160; I started the connection and I was logged in without using a password.&#160; It authenticated me using the private key (and the passphrase for the key if you set it).<\/p>\n<p>Now it is possible to disable log via SSH on using passwords.&#160; You\u2019ll do this to force people to us their private key instead of a weaker password that could be subject to brute force attacks.<\/p>\n<p>The first is to change PasswordAuthentication to have a value of \u201cno\u201d.&#160; You may need to remove the comment\/remark symbol of # from the start of the line.&#160; I also found that I had to set UsePam to a value of \u201cno\u201d.&#160; That meant these two lines were in the file in different locations:<\/p>\n<p align=\"center\">PasswordAuthentication no<\/p>\n<p align=\"center\">UsePam no<\/p>\n<p>Again I restarted SSH using rcsshd restart.&#160; Now I tested two things:<\/p>\n<ol>\n<li>I tried to login using Putty and my username and password.&#160; The initial connection failed.<\/li>\n<li>I logged in using my private key.&#160; That worked.<\/li>\n<\/ol>\n<p>Perfect.&#160; Now I can use SSH to log into the Linux box without the worry of weak passwords being used by users on the machine.&#160; They are forced into using stronger public\/private key pairs.&#160; And I can sleep safe knowing that the machine is not vulnerable to brute force password attacks.<\/p>\n<div style=\"padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px\" id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:60c3f6ca-5d19-4b78-8e19-f6381fef93b0\" class=\"wlWriterEditableSmartContent\">Technorati Tags: <a href=\"http:\/\/technorati.com\/tags\/Linux\" rel=\"tag\">Linux<\/a>,<a href=\"http:\/\/technorati.com\/tags\/Security\" rel=\"tag\">Security<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I needed to set up key based, rather than password based, access to SUSE Linux Enterprise Server.&#160; It\u2019s more secure because it uses a public\/private key pair rather than a password.&#160; The user\u2019s private key is stored on the client.&#160; The private key for the user is stored on the Linux machines.&#160; When they connect &hellip; <a href=\"https:\/\/aidanfinn.com\/?p=10283\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Setting Up Public Key Based SSH Access To SLES&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[24],"tags":[184,190],"class_list":["post-10283","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux","tag-security"],"aioseo_notices":[],"jetpack_featured_media_url":"","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/posts\/10283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10283"}],"version-history":[{"count":0,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/posts\/10283\/revisions"}],"wp:attachment":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}