{"id":1132,"date":"2020-04-29T16:46:18","date_gmt":"2020-04-29T15:46:18","guid":{"rendered":"https:\/\/portal.supercomputing.wales\/?page_id=1132"},"modified":"2020-06-22T22:27:19","modified_gmt":"2020-06-22T21:27:19","slug":"password-less-access-with-private-keys","status":"publish","type":"page","link":"https:\/\/portal.supercomputing.wales\/index.php\/index\/password-less-access-with-private-keys\/","title":{"rendered":"Password less access with private keys on Windows"},"content":{"rendered":"\n<p>It is possible to configure some common Windows applications such as PuTTY and WinSCP to access our systems without entering a password at every login. This method uses passphrase protected public-private key pairs, a cryptographic system where the public key is disseminated to the remote system that require secure access. Remote systems authenticate users by encrypting a message using the public key that can only be decrypted with the private key hold by the user. The strength of this system relies on keeping the private key private, using it on systems only accessible by the user (e.g. private laptops, desktops).<\/p> <h2 class=\"wp-block-heading\">Generate Public\/Private key pair<\/h2> <p>To generate a public\/private key pair we can use PuTTYgen, an application commonly installed as part of PuTTY.<\/p> <figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-1.png\" alt=\"\" class=\"wp-image-1133\" width=\"507\" height=\"547\" srcset=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-1.png 676w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-1-278x300.png 278w\" sizes=\"auto, (max-width: 507px) 100vw, 507px\" \/><\/figure> <p>To create a new key pair, select the type of key to generate from the bottom of the screen, ED25519 is the type of key that we recommended. Then click \u201cGenerate\u201d, and start moving the mouse within the Window.<\/p> <figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/PuTTYgen-ed25519-01-marked.png\" alt=\"\" class=\"wp-image-1178\" width=\"476\" height=\"464\" srcset=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/PuTTYgen-ed25519-01-marked.png 1021w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/PuTTYgen-ed25519-01-marked-300x293.png 300w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/PuTTYgen-ed25519-01-marked-768x751.png 768w\" sizes=\"auto, (max-width: 476px) 100vw, 476px\" \/><\/figure> <figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"477\" height=\"465\" src=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/PuTTYgen-ed25519-02.png\" alt=\"\" class=\"wp-image-1179\" srcset=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/PuTTYgen-ed25519-02.png 477w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/PuTTYgen-ed25519-02-300x292.png 300w\" sizes=\"auto, (max-width: 477px) 100vw, 477px\" \/><\/figure> <p><em><u>Setting up a passphrase<\/u><\/em><\/p> <p>At this point it is\u00a0<strong>highly recommended<\/strong> to add a passphrase to your private key. This will add an extra layer of protection in case the file is compromised. Without a passphrase an attacker that successfully gains access to your private key, will also obtain access to the remote server.\u00a0<\/p> <p>Passphrases are typically longer than passwords. An example of a passphrase would be: I,L1k3,C0l0rl355,R41nb0w5!?&nbsp;<\/p> <p><em><u>Save the private key&nbsp;<\/u><\/em><\/p> <p>Save at least the private key by clicking Save private key. At this point you can copy or save the public key by clicking Save public key (but bear in mind that PuTTY saves this file in a format non compatible with SCW systems). You can always regenerate the public key in a compatible format by loading the private key file (by clicking Load).<\/p> <p><\/p> <figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/PuTTYgen-ed25519-03-marked.png\" alt=\"\" class=\"wp-image-1180\" width=\"479\" height=\"461\" srcset=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/PuTTYgen-ed25519-03-marked.png 1021w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/PuTTYgen-ed25519-03-marked-300x289.png 300w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/PuTTYgen-ed25519-03-marked-768x741.png 768w\" sizes=\"auto, (max-width: 479px) 100vw, 479px\" \/><\/figure> <p><em><u>Not writing your passphrase every time.<\/u><\/em><\/p> <p>The main difference between passwords and passphrases is that while for the former you need to enter them every time you login into the system, passphrases allow you to enter them once per session providing\u00a0<strong>a compromise between improved security and convenience<\/strong>. To do this you can use Windows\u2019 SSH authentication agent Pageant (which is typically installed with PuTTY). Double click on your saved private key file and enter your passphrase on the newly opened window. If successful, Pageant, will put an icon of a computer wearing a hat into the System tray.\u00a0<\/p> <figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"614\" src=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/pageant-1-1024x614.png\" alt=\"\" class=\"wp-image-1181\" srcset=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/pageant-1-1024x614.png 1024w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/pageant-1-300x180.png 300w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/pageant-1-768x460.png 768w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/pageant-1-1536x921.png 1536w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/pageant-1.png 1608w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure> <p>Now you can use your private key with PuTTY without entering your passphrase while Pageant is running (notice that closing Pageant window does not stop the application).<\/p> <p><em><u>Using more than one private key<\/u><\/em><\/p> <p>Although is possible to use a single private key for multiple servers (e.g. Hawk, Sunbird, Github) this is not recommended as it increases the number of targets put at risk if the key becomes compromised. A better practise instead is to use a different private key for each remote server. Pageant can be used to manage different private keys by opening the application. Click the Pageant icon in the system tray (or search for Pageant in Windows\u2019 start menu) with the right mouse button, you will see a menu. Select \u2018View Keys\u2019 from this menu. The Pageant main window will appear.<\/p> <figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"512\" height=\"364\" src=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/pageant-2.png\" alt=\"\" class=\"wp-image-1182\" srcset=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/pageant-2.png 512w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/06\/pageant-2-300x213.png 300w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/figure> <p>In this window you can add additional private keys for different servers, if these are passphrase protected Pageant will prompt you for the passphrase.<\/p> <h2 class=\"wp-block-heading\">Installing the public key as an authorized key on SCW systems<\/h2> <p>The public key needs to be added to the authorized keys file. The public key needs to be added to the authorized keys file on the remote server. WinSCP >= 5.14 allows to automatically add the public key to this file (you must first login using your password), for this use Session -> Install Public Key into Server command on the main window, or Tools -> Install Public Key into Servercommand on SSH -> Authentication page on Advanced Site Settings dialog.\u00a0<\/p> <p>If you have an older version of WinSCP or prefer to do it manually, login to the system and edit the file located in your home directory in <em>\/home\/your_username\/.ssh\/authorized_keys<\/em>. This can be done in the command line with your preferred text editor (if using WinSCP, make sure to enable \u201cShow hidden files\u201d in <em>Options -&gt; Preferences -&gt; Panels<\/em> to show the .ssh folder). <\/p> <h2 class=\"wp-block-heading\">Enable access with private key from PuTTY<\/h2> <p>Open PuTTY and navigate to Connection -&gt; SSH -&gt; Auth on the left hand pane. Browse for the private key file previously generated. Go back to Session and amend your details if needed or click Open. If the private key is passphrase protected (recommended) and is already loaded with Pageant, you should be able to access the system without entering your password, otherwise you will be prompted to enter the passphrase.<\/p> <figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"481\" height=\"468\" src=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-5-1.png\" alt=\"\" class=\"wp-image-1139\" srcset=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-5-1.png 481w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-5-1-300x292.png 300w\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" \/><\/figure> <h2 class=\"wp-block-heading\">Enable access with private keys from WinSCP<\/h2> <p>Open WinSCP. In the login window click on Edit, Advanced, navigate to SSH -&gt; Authentication, click on the three dots and look for the private key file. Ok and Save. As with PuTTY, If the private key is passphrase protected (recommended) and is already loaded with Pageant, you should be able to access the system without entering your password, otherwise you will be prompted to enter the passphrase.&nbsp;<\/p> <figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"690\" height=\"474\" src=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-6-1.png\" alt=\"\" class=\"wp-image-1141\" srcset=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-6-1.png 690w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-6-1-300x206.png 300w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/figure> <figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"690\" height=\"470\" src=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-7.png\" alt=\"\" class=\"wp-image-1142\" srcset=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-7.png 690w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-7-300x204.png 300w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/figure> <figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"514\" src=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-8.png\" alt=\"\" class=\"wp-image-1143\" srcset=\"https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-8.png 617w, https:\/\/portal.supercomputing.wales\/wp-content\/uploads\/2020\/04\/puttygen-8-300x250.png 300w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/figure> <p>\u000e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is possible to configure some common Windows applications such as PuTTY and WinSCP to access our systems without entering a password at every login. This method uses passphrase protected public-private key pairs, a cryptographic system where the public key is disseminated to the remote system that require secure access. Remote systems authenticate users by [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"parent":5,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_lmt_disableupdate":"no","_lmt_disable":"","footnotes":""},"class_list":["post-1132","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/pages\/1132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/comments?post=1132"}],"version-history":[{"count":4,"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/pages\/1132\/revisions"}],"predecessor-version":[{"id":1186,"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/pages\/1132\/revisions\/1186"}],"up":[{"embeddable":true,"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/pages\/5"}],"wp:attachment":[{"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/media?parent=1132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}