{"id":44,"date":"2015-08-11T08:56:37","date_gmt":"2015-08-11T07:56:37","guid":{"rendered":"http:\/\/www.haxed.me.uk\/?p=44"},"modified":"2015-08-11T15:53:26","modified_gmt":"2015-08-11T14:53:26","slug":"howto-ssh-with-keys","status":"publish","type":"post","link":"https:\/\/haxed.me.uk\/index.php\/2015\/08\/11\/howto-ssh-with-keys\/","title":{"rendered":"HOWTO: SSH with KEYS"},"content":{"rendered":"<p>So, at work yesterday it was suggested to me that I should setup SSH with keys as to avoid the pain caused by attempts to continually use credentials for specific servers I run.<\/p>\n<p>Doing this might seem daunting to the uninitiated, so here is how I did it between my box and the server I wanted to login with an SSH key instead of regular password. Please note there are some security implications from using SSH keys as opposed to password.<\/p>\n<p>Step 1:\u00a0 Generate your pair of keys. (2 keys will be made, one for the remote server, and one for your own machine).<\/p>\n<blockquote><p>ssh-keygen -t dsa<\/p>\n<pre>Generating public\/private dsa key pair.\r\nEnter file in which to save the key (\/home\/adam\/.ssh\/id_dsa): \r\nEnter passphrase (empty for no passphrase): \r\nEnter same passphrase again: \r\nYour identification has been saved in \/home\/adam\/.ssh\/id_dsa.\r\nYour public key has been saved in \/home\/adam\/.ssh\/id_dsa.pub.\r\nThe key fingerprint is:\r\n1d:ab:23:29:9f:d6:7c:3c:39:ab:2b:2c:8f:2f:4d:26 adam@mylocal\r\n<\/pre>\n<\/blockquote>\n<p>Step 2:\u00a0 your keys are stored, by default in your &#8216;users&#8217; .ssh folder or ~<\/p>\n<blockquote><p>cd ~.ssh; ls -l<\/p>\n<pre>-rw-------    1 adam     adam          526 Nov  3 01:21 id_dsa\r\n-rw-r--r--    1 adam     adam          330 Nov  3 01:21 id_dsa.pub\r\n<\/pre>\n<\/blockquote>\n<p>Step 3: Observe your beautiful keys.<\/p>\n<p>&#8212; id_dsa is your private key. Keep this on the machine you want to login <strong>FROM. <\/strong>Do not share the key otherwise it will allow other people to login to your machine. <strong>very bad.<\/strong><\/p>\n<p>&#8212; id_dsa.pub is your public key. This can be added to the system you want to login to authorized_keys2 file.<\/p>\n<p>Step 4: Place the public key on the remote server. I simply used scp from the terminal to copy the public key file to the remote server I want to <strong>login to<\/strong>.<\/p>\n<blockquote><p>scp id_dsa.pub adam@myremoteserver.business.com:.\/id_dsa.pub<\/p><\/blockquote>\n<p>If it works you&#8217;ll see a status bar show 100% , 607bytes, Kb\/s 0:00 and the time taken to transfer the file<\/p>\n<p>Step 5: Login to the remote server and make public key ready to be used. It is very important these commands are written in this order.<\/p>\n<blockquote><p># switch to home dir and make sure .ssh folder exists<br \/>\ncd ~; mkdir .ssh;<br \/>\ncd .ssh<\/p>\n<p># make sure that the key file is there<br \/>\ntouch authorized_keys2<\/p>\n<p># add key to authorize_keys2 file<\/p>\n<p>cat ..\/id_dsa.pub &gt;&gt; authorized_keys2<br \/>\nrm ..\/id_dsa.pub<\/p><\/blockquote>\n<p>Step 6:\u00a0 Ensure correct permissions on the filesystem for &#8216;secret&#8217; file<\/p>\n<blockquote><p>chmod 600 authorized_keys2<\/p><\/blockquote>\n<p>Step 7: Login using your new ssh keypair<\/p>\n<blockquote><p>ssh -2 -v adam@myremoteserver.business.com<br \/>\ndebug1: Trying private key: \/Users\/adam\/.ssh\/id_rsa<br \/>\ndebug1: Offering DSA public key: \/Users\/adam\/.ssh\/id_dsa<\/p><\/blockquote>\n<p>Job done!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, at work yesterday it was suggested to me that I should setup SSH with keys as to avoid the pain caused by attempts to continually use credentials for specific servers I run. Doing this might seem daunting to the &hellip; <a href=\"https:\/\/haxed.me.uk\/index.php\/2015\/08\/11\/howto-ssh-with-keys\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/comments?post=44"}],"version-history":[{"count":0,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/44\/revisions"}],"wp:attachment":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/media?parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/categories?post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/tags?post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}