{"id":389,"date":"2023-03-10T01:07:20","date_gmt":"2023-03-10T01:07:20","guid":{"rendered":"https:\/\/blog.inplico.uk\/?p=389"},"modified":"2023-03-10T01:08:24","modified_gmt":"2023-03-10T01:08:24","slug":"putty-login-to-linux-box-with-ssh-keys","status":"publish","type":"post","link":"https:\/\/blog.inplico.uk\/?p=389","title":{"rendered":"putty login to linux box with ssh keys"},"content":{"rendered":"<p>Most of the instructions I have found tell you to generate a key with with puttygen however I have had no success getting it to work this way.\u00a0 The best way I have found is to use linux to generate a key pair, copy the public key on to the server as per per ssh notes, get the private on to the client using whatever means you see fit and then use puttygen to convert the key to something putty can comprehend.<\/p>\n<p>Navigate to a suitable directory (does not have to be ~\/.ssh, in fact it would be better to put the keys somewhere else).<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\">mkdir mykeypair\r\n\r\nssh-keygen -t rsa -b 4096 -C mykeypair_rsa -f mykeypair_rsa<\/pre>\n<p>Don&#8217;t set a password as doing so kinda defeats the object.<\/p>\n<p>Now you should have 2 files in the directory you created.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Server<\/strong><\/span><\/p>\n<p>Next you need to copy the public key to the server:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ssh-copy-id \u2013i mykeypair_rsa.pub myUserName@myServer<\/pre>\n<p>You will be prompted to enter your password. This command essentially adds the key to the user&#8217;s authorized_keys file on the server and if successful should display:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Number of key(s) added: 1\r\n\r\nNow try logging into the machine, with:   \"ssh 'myUserName@myServer'\"\r\nand check to make sure that only the key(s) you wanted were added.\r\n<\/pre>\n<p>That is it for the server; now for the client:<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Client<\/strong><\/span><\/p>\n<p>Find a way to get the private key (The file that doesn&#8217;t end in &#8220;pub&#8221; on to the client)\u00a0 You can copy and paste the contents if you like. Now start puttygen and hit the <strong>&#8220;load an existing private key file&#8221;<\/strong> button.\u00a0 You should be notified that the key was successfully imported.\u00a0 Click &#8220;OK&#8221;<\/p>\n<p>This converts the private key to a format that putty can understand, now click &#8220;save private key&#8221; and save it in a location only accessible by the logged on user (unless you want all users to be granted access).<\/p>\n<p>Now open putty and load your session (configuration of a session is beyond the scope of this how to).\u00a0 Next navigate to <strong>SSH &gt; Auth &gt; Credentials<\/strong> and click <strong>&#8220;Browse&#8221;<\/strong> next to the <strong>&#8220;Private key file for authentication&#8221;<\/strong> field.\u00a0 Now navigate to the private keyfile you saved earlier and that should be it, you can now log on without authenticating first.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Create a shortcut<\/strong><\/span><\/p>\n<p>Finally you may want to create a shortcut to automatically open you session, do do so right click and select <strong>new &gt; shortcut<\/strong> from the popup menu.\u00a0 In the dialogue box browse to &#8220;C:\\program files\\putty\\putty&#8221; now append the location with -load mysessionname (where mysessionname is the name you have given to your session.\u00a0 Now you can name your shortcut and you are done.<\/p>\n<p>The shortcut will look something like:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\"C:\\program files\\putty\\putty\" -load mysessionname<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most of the instructions I have found tell you to generate a key with with puttygen however I have had no success getting it to work this way.\u00a0 The best way I have found is to use linux to generate a key pair, copy the public key on to the server as per per ssh [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-389","post","type-post","status-publish","format-standard","hentry","category-debian-server"],"_links":{"self":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts\/389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=389"}],"version-history":[{"count":4,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts\/389\/revisions"}],"predecessor-version":[{"id":393,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts\/389\/revisions\/393"}],"wp:attachment":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}