{"id":9250,"date":"2013-10-16T20:32:01","date_gmt":"2013-10-17T01:32:01","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=9250"},"modified":"2018-09-17T18:27:47","modified_gmt":"2018-09-17T23:27:47","slug":"putty-public-key-authentication","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=9250","title":{"rendered":"Putty Public Key Authentication"},"content":{"rendered":"<div class='toc wptoc'>\n<h2>Contents<\/h2>\n<ol class='toc-odd level-1'>\n\t<li>\n\t\t<a href=\"#On_Client_Machine\">On Client Machine<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Generate_PrivatePublic_Key_Pair_with_PUTTYGEN.EXE\">Generate Private\/Public Key Pair with <em>PUTTYGEN.EXE<\/em><\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Save_Private_Key\">Save Private Key<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#On_SSH_Server_Machine\">On SSH Server Machine<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Setup_authorized_keys2_File\">Setup <em>authorized_keys2<\/em> File<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#Configure_Private_Key_for_PuTTY_Session\">Configure Private Key for PuTTY Session<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Add_Private_key_to_PuTTY_SSH_Authentication_Agent\">Add Private key to PuTTY SSH Authentication Agent<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Start_PuTTY_Session\">Start PuTTY Session<\/a>\n\t\t\t<\/li>\n<\/ol>\n<\/ol>\n<\/ol>\n<\/div>\n<div class='wptoc-end'>&nbsp;<\/div>\n<span id=\"On_Client_Machine\"><h2>On Client Machine<\/h2><\/span>\n<span id=\"Generate_PrivatePublic_Key_Pair_with_PUTTYGEN.EXE\"><h3>Generate Private\/Public Key Pair with <em>PUTTYGEN.EXE<\/em><\/h3><\/span>\n<p>* Change directory to PuTTY installation directory, e.g. <em>C:\\prog\\PuTTY<\/em><br \/>\n* Double click <em>PUTTYGEN.EXE<\/em><br \/>\n* Select:<br \/>\n&#8211; Type of key to generate: <em>SSH-2 RSA<\/em><br \/>\n&#8211; Number of bits in a generated key: <strong>2048<\/strong><br \/>\n* Click <em>Generate<\/em><br \/>\n* Move the mouse around in the Key area<br \/>\n* Private\/public key pair is generated:<\/p>\n<span id=\"\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_gen.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_gen-300x290.jpg\" alt=\"\" title=\"putty_pubKey_gen\" width=\"300\" height=\"290\" class=\"aligncenter size-medium wp-image-9251\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_gen-300x290.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_gen.jpg 472w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h6><\/span>\n<span id=\"Save_Private_Key\"><h3>Save Private Key<\/h3><\/span>\n<p>* Enter:<br \/>\n&#8211; Key passphrase:<br \/>\n&#8211; Confirm passphrase:<br \/>\n* Click <em>Save private key<\/em> and save private key to a local directory, e.g. <em>C:\\Users\\jimmy\\MyPuTTYPrivateKey.ppk<\/em><\/p>\n<span id=\"_1\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_saveKey.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_saveKey-300x289.jpg\" alt=\"\" title=\"putty_pubKey_saveKey\" width=\"300\" height=\"289\" class=\"aligncenter size-medium wp-image-9252\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_saveKey-300x289.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_saveKey.jpg 477w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h6><\/span>\n<p>* You don&#8217;t need to save public key for this exercise<\/p>\n<span id=\"On_SSH_Server_Machine\"><h2>On SSH Server Machine<\/h2><\/span>\n<span id=\"Setup_authorized_keys2_File\"><h3>Setup <em>authorized_keys2<\/em> File<\/h3><\/span>\n<p>* SSH into server machine with password authentication for now<br \/>\n* Change directory to user&#8217;s home directory<br \/>\n* Make a new directory named <strong>.ssh<\/strong> if it does not exist already:<br \/>\n* Change directory to <em>.ssh<\/em> directory:<br \/>\n* Check <em>\/etc\/ssh\/sshd_config<\/em> file for the name of the AuthorizedKeysFile, e.g.<\/p>\n<pre lang=\"bash\">\r\nAuthorizedKeysFile .ssh\/authorized_keys2\r\n<\/pre>\n<p>* Open or create a file named <em>authorized_keys2<\/em>:<\/p>\n<pre lang=\"bash\">\r\ncd ~\r\nmkdir .ssh\r\nchmod 700 .ssh\r\ncd ~\/.ssh\r\nvi authorized_keys2\r\n<\/pre>\n<p>* Copy and paste the public key from PuTTY Key Generator window<\/p>\n<span id=\"_2\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_copyPubKey.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_copyPubKey-300x289.jpg\" alt=\"\" title=\"putty_pubKey_copyPubKey\" width=\"300\" height=\"289\" class=\"aligncenter size-medium wp-image-9256\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_copyPubKey-300x289.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_copyPubKey.jpg 475w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h6><\/span>\n<p>to the <em>authorized_keys2<\/em> file:<\/p>\n<span id=\"_3\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_copyPubKey_2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_copyPubKey_2-300x41.jpg\" alt=\"\" title=\"putty_pubKey_copyPubKey_2\" width=\"300\" height=\"41\" class=\"aligncenter size-medium wp-image-9257\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_copyPubKey_2-300x41.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_copyPubKey_2.jpg 647w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h6><\/span>\n<p>* Alternatively, you can convert SSH2 public key to OpenSSH key before appending to <em>authorized_keys2<\/em> with following command:<\/p>\n<pre lang=\"bash\">\r\nssh-keygen -i -f ~\/.ssh\/ssh2_key.pub >> ~\/.ssh\/authorized_keys2\r\n<\/pre>\n<p>* chmod for <em>authorized_keys2<\/em><\/p>\n<pre lang=\"bash\">\r\nchmod 600 authorized_keys2\r\n<\/pre>\n<span id=\"Configure_Private_Key_for_PuTTY_Session\"><h2>Configure Private Key for PuTTY Session<\/h2><\/span>\n<span id=\"Add_Private_key_to_PuTTY_SSH_Authentication_Agent\"><h3>Add Private key to PuTTY SSH Authentication Agent<\/h3><\/span>\n<p>* Go to the PuTTY program directory<br \/>\n* Double click <em>PAGEANT.EXE<\/em> file<br \/>\n&#8211; Agent is open up in the task panel<\/p>\n<span id=\"_4\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_pageant_icon.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_pageant_icon.jpg\" alt=\"\" title=\"putty_pubKey_pageant_icon\" width=\"146\" height=\"42\" class=\"aligncenter size-full wp-image-9253\" \/><\/a><\/h6><\/span>\n<p>* Right click the agent icon in the task panel and select <em>Add Key<\/em><\/p>\n<span id=\"_5\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_pageant_addKey.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_pageant_addKey.jpg\" alt=\"\" title=\"putty_pubKey_pageant_addKey\" width=\"113\" height=\"154\" class=\"aligncenter size-full wp-image-9254\" \/><\/a><\/h6><\/span>\n<p>* Browse to <em>myPuTTYPrivateKey.ppk<\/em> file and click <em>Open<\/em><br \/>\n* Enter <em>passphase for key<\/em> and click <em>OK<\/em>:<\/p>\n<span id=\"_6\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_pageant_addKey_pass.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_pageant_addKey_pass.jpg\" alt=\"\" title=\"putty_pubKey_pageant_addKey_pass\" width=\"211\" height=\"117\" class=\"aligncenter size-full wp-image-9255\" \/><\/a><\/h6><\/span>\n<span id=\"Start_PuTTY_Session\"><h3>Start PuTTY Session<\/h3><\/span>\n<p>* Open <em>PuTTY<\/em><br \/>\n* Load a saved session<br \/>\n* Select <em>Connection > SSH > Auth<\/em><br \/>\n* Set <em>Private key file for authentication<\/em> to private key file: <strong>C:\\Users\\Jimmy\\MyPrivateKey.ppk<\/strong><\/p>\n<span id=\"_7\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_use_setKey.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_use_setKey-300x284.jpg\" alt=\"\" title=\"putty_pubKey_use_setKey\" width=\"300\" height=\"284\" class=\"aligncenter size-medium wp-image-9258\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_use_setKey-300x284.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_use_setKey.jpg 452w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h6><\/span>\n<p>* Set Host Name in the format: <em>user@server<\/em>, e.g. oracle@dbserver<\/p>\n<span id=\"_8\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_use_setHostname.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_use_setHostname-300x83.jpg\" alt=\"\" title=\"putty_pubKey_use_setHostname\" width=\"300\" height=\"83\" class=\"aligncenter size-medium wp-image-9259\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_use_setHostname-300x83.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2013\/10\/putty_pubKey_use_setHostname.jpg 450w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h6><\/span>\n<p>* Save the session again<br \/>\n* Click Open to start the session. You should be able to login without password.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>On Client Machine Generate Private\/Public Key Pair with PUTTYGEN.EXE * Change directory to PuTTY installation directory, e.g. C:\\prog\\PuTTY * Double click PUTTYGEN.EXE * Select: &#8211; Type of key to generate: SSH-2 RSA &#8211; Number of bits in a generated key: &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=9250\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[451],"tags":[452,639],"class_list":["post-9250","post","type-post","status-publish","format-standard","hentry","category-ssh","tag-putty","tag-ssh"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-2pc","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/9250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9250"}],"version-history":[{"count":6,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/9250\/revisions"}],"predecessor-version":[{"id":12251,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/9250\/revisions\/12251"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}