{"id":345,"date":"2017-05-27T08:38:02","date_gmt":"2017-05-27T08:38:02","guid":{"rendered":"http:\/\/chewett.co.uk\/blog\/?p=345"},"modified":"2018-05-19T22:13:50","modified_gmt":"2018-05-19T21:13:50","slug":"ssh-access-passwordless-keyfile","status":"publish","type":"post","link":"https:\/\/chewett.co.uk\/blog\/345\/ssh-access-passwordless-keyfile\/","title":{"rendered":"SSH access with passwordless keyfile"},"content":{"rendered":"<p>I want to be able to access my Raspberry Pi Cluster and log onto any node without entering a password. To do this I can set up as passwordless SSH key.<\/p>\n<h2>Generating a SSH Key<\/h2>\n<p>To generate a SSH key you can use the command <code>ssh-keygen<\/code>. Once you have ran this you will get the below command output.<\/p>\n<pre>chewett@bunker-master:\/tmp$ <strong>ssh-keygen<\/strong>\r\nGenerating public\/private rsa key pair.\r\nEnter file in which to save the key (\/home\/chewett\/.ssh\/id_rsa):\r\nEnter passphrase (empty for no passphrase):\r\nEnter same passphrase again:\r\nYour identification has been saved in \/home\/chewett\/.ssh\/id_rsa.\r\nYour public key has been saved in \/home\/chewett\/.ssh\/id_rsa.pub.\r\nThe key fingerprint is:\r\n08:da:bf:3b:40:60:19:62:a8:97:10:77:e1:c9:93:d8 chewett@bunker-master\r\nThe key's randomart image is:\r\n+---[RSA 2048]----+\r\n|+oooo.           |\r\n|+o+* o           |\r\n|.o.oE            |\r\n|. oo.o .         |\r\n| .... . S        |\r\n|    ..           |\r\n|     ..          |\r\n|      ..         |\r\n|      oo         |\r\n+-----------------+<\/pre>\n<p>&nbsp;<\/p>\n<p>During this command you can choose where the store the key files and what passphrase you want to secure the key with. For this I have not set a passphrase so I don&#8217;t need to enter it when logging into my cluster.<\/p>\n<p>Once I have ran this command it will generate a public and private key. This private key is used in combination with the public key to authenticate yourself. I will install the public key\u00a0on any machine that I want to login to and it will give access via the private key. As suggested by the name the public key can be installed on all your machines and the private one should be kept private.<\/p>\n<h2>Installing the public key<\/h2>\n<p>Once you have generated your public key you need to copy it to all the machines you want to access it on. To install it you need to add it \u00a0into the authorized_keys file. This is located in <code>~\/.ssh\/authorized_keys<\/code>. You can copy your public key to the machine and install it using.<\/p>\n<pre>scp \u00a0\/home\/chewett\/.ssh\/id_rsa.pub bunker-master:~\/\r\nssh bunker-master\r\nmkdir ~\/.ssh\/\r\ncat id_rs.pub &gt;&gt; ~\/.ssh\/authorized_keys<\/pre>\n<p>The first line copies the public key to the machine. Once this has been done you can login to the remote server (second line). If the <code>~\/.ssh\/<\/code> directory does not exist it can be created with <code>mkdir<\/code>. Using <code>cat<\/code>\u00a0you can then echo your public key and append it to the <code>authorized_keys<\/code> file. We want to ensure we append to this file using <code>&gt;&gt;<\/code>. This is because if the file exists we want to add your public key and not lose the other lines in this file.<\/p>\n<h2>Logging in with the SSH key<\/h2>\n<p>Now \u00a0we \u00a0have installed the SSH public key we can login to the machine using<\/p>\n<pre>ssh -i ~\/.ssh\/id_rsa bunker-master<\/pre>\n<p>Using the <code>-i<\/code> flag you can specify which key file you want to use to ssh into the host. If you don&#8217;t want to enter this each time you can specify this in your SSH config file. This file should be found, or created, in <code>~\/.ssh\/config<\/code><\/p>\n<pre>Host bunker-master\r\n HostName 192.168.0.5\r\n User chewett\r\n IdentityFile ~\/.ssh\/id_rsa<\/pre>\n<p>The format for the file is above. Host is the name you want to refer to the machine as. HostName is the IP or hostname of the machine that will be used to SSH to. User can be specified to set the username used to SSH in and IdentityFile will specify the keyfile you want to use when logging.<\/p>\n<p>If I set my config file up as above, all I would need to do so is type <code>ssh bunker-master<\/code> and this would effectively run <code>ssh -i ~\/.ssh\/id_rsa chewett@192.168.0.5<\/code>. The first being much shorter.<\/p>\n<p>In addition to being able to specify all the options in the config file, using a keyfile means you don&#8217;t need to enter your password. Since I didn&#8217;t enter a password for my keyfile entering <code>ssh bunker-master<\/code> will automatically ssh into the host and log me in.<\/p>\n<p>Once I have installed this on all of my nodes I will be able to SSH into any one of them without needing a password. Performing this will be important for automatically running commands on the nodes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I want to be able to access my Raspberry Pi Cluster and log onto any node without entering a password. To do this I can set up as passwordless SSH key. Generating a SSH Key To generate a SSH key you can use the command ssh-keygen. Once you have ran this you will get the [&hellip;]<\/p>\n","protected":false},"author":1,"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":false,"_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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[122],"tags":[39,90],"class_list":["post-345","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi-cluster","tag-linux","tag-ssh"],"wppr_data":{"cwp_meta_box_check":"No"},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2toWX-5z","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1197,"url":"https:\/\/chewett.co.uk\/blog\/1197\/removing-a-passphrase-from-a-ssh-key\/","url_meta":{"origin":345,"position":0},"title":"Removing a passphrase from a SSH key","author":"Chewett","date":"May 23, 2018","format":false,"excerpt":"Here I explain how you can remove a passphrase from a SSH key. Why would you want to do this? There may be cases where you have deployed a SSH\u00a0key with a passphrase but now want to use it in a script. While you can add the key to the\u2026","rel":"","context":"In &quot;Informational&quot;","block_context":{"text":"Informational","link":"https:\/\/chewett.co.uk\/blog\/category\/informational\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/05\/removing_passphrase_ssh.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/05\/removing_passphrase_ssh.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/05\/removing_passphrase_ssh.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/05\/removing_passphrase_ssh.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":407,"url":"https:\/\/chewett.co.uk\/blog\/407\/ssh-connect-host-raspberrypi-port-22-connection-refused-error-fixed\/","url_meta":{"origin":345,"position":1},"title":"ssh: connect to host raspberrypi port 22: Connection refused Error Fixed","author":"Chewett","date":"June 24, 2017","format":false,"excerpt":"I was setting up a new install of Raspbian Pixel and found I couldn't login to the Raspberry Pi. It was giving me an error: chewett@bunker-master:~$ ssh pi@raspberrypi ssh: connect to host raspberrypi port 22: Connection refused It turns out that recently the Raspberry Pi Foundation have changed the default\u2026","rel":"","context":"In &quot;Raspberry Pi Cluster&quot;","block_context":{"text":"Raspberry Pi Cluster","link":"https:\/\/chewett.co.uk\/blog\/category\/raspberry-pi-cluster\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":461,"url":"https:\/\/chewett.co.uk\/blog\/461\/updating-raspberry-pi-cluster-without-logging-every-pi\/","url_meta":{"origin":345,"position":2},"title":"Updating the Raspberry Pi Cluster without logging in to every Pi","author":"Chewett","date":"July 1, 2017","format":false,"excerpt":"The Raspberry Pi foundation have recently updated their Raspbian image. This brings bugfixes and upgrades to the Raspberry Pi. In this blogpost I share how you can run a command on your Raspberry Pi without logging in (this is mostly true although you still do \"log in\" just not in\u2026","rel":"","context":"In &quot;Raspberry Pi Cluster&quot;","block_context":{"text":"Raspberry Pi Cluster","link":"https:\/\/chewett.co.uk\/blog\/category\/raspberry-pi-cluster\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2017\/07\/raspbian_update_command.png?fit=580%2C307&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2017\/07\/raspbian_update_command.png?fit=580%2C307&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2017\/07\/raspbian_update_command.png?fit=580%2C307&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":409,"url":"https:\/\/chewett.co.uk\/blog\/409\/setting-raspberry-pi-cluster-node\/","url_meta":{"origin":345,"position":3},"title":"Setting up a Raspberry Pi Cluster Node","author":"Chewett","date":"August 19, 2017","format":false,"excerpt":"To set up a Raspberry Pi node I will follow a specific set of steps so that every Pi is set up \u00a0similarly. For the initial deployment I will follow this once and then clone the SD Card multiple times. If at a later date more are added I will\u2026","rel":"","context":"In &quot;Raspberry Pi Cluster&quot;","block_context":{"text":"Raspberry Pi Cluster","link":"https:\/\/chewett.co.uk\/blog\/category\/raspberry-pi-cluster\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2017\/08\/setting_up_a_raspi_cluster_node.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2017\/08\/setting_up_a_raspi_cluster_node.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2017\/08\/setting_up_a_raspi_cluster_node.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2017\/08\/setting_up_a_raspi_cluster_node.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":375,"url":"https:\/\/chewett.co.uk\/blog\/375\/setting-up-the-ci20-for-the-cluster\/","url_meta":{"origin":345,"position":4},"title":"Setting up the CI20 for the cluster","author":"Chewett","date":"October 27, 2018","format":false,"excerpt":"This post talks about the steps I have followed to set up my Creator CI20 for the Raspberry Pi Cluster. Burning Debian to the onboard NAND and configuring it To run the CI20 on the Raspberry Pi Cluster I am going to write Debian 8 to the NAND storage. First\u2026","rel":"","context":"In &quot;Raspberry Pi Cluster&quot;","block_context":{"text":"Raspberry Pi Cluster","link":"https:\/\/chewett.co.uk\/blog\/category\/raspberry-pi-cluster\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/10\/ci40_setup.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/10\/ci40_setup.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/10\/ci40_setup.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/10\/ci40_setup.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":2535,"url":"https:\/\/chewett.co.uk\/blog\/2535\/fixing-ssh-keygen-unknown-option-g-or-t-on-ubuntu-20-04\/","url_meta":{"origin":345,"position":5},"title":"Fixing ssh-keygen Unknown Option -G or -T on Ubuntu 20.04","author":"Chewett","date":"July 4, 2020","format":false,"excerpt":"This blog post talks about how you can resolve the problem \"ssh-keygen Unknown Option -G\" on Ubuntu 20.04. What is ssh-keygen -G and -T used for? The command ssh-keygen -G was originally used to generate a list of prime numbers that could be used for key exchange. Typically the list\u2026","rel":"","context":"In &quot;Fixes&quot;","block_context":{"text":"Fixes","link":"https:\/\/chewett.co.uk\/blog\/category\/fixes\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2020\/07\/sshkeygen_ubuntu2004-1.jpg?fit=1200%2C628&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2020\/07\/sshkeygen_ubuntu2004-1.jpg?fit=1200%2C628&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2020\/07\/sshkeygen_ubuntu2004-1.jpg?fit=1200%2C628&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2020\/07\/sshkeygen_ubuntu2004-1.jpg?fit=1200%2C628&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2020\/07\/sshkeygen_ubuntu2004-1.jpg?fit=1200%2C628&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/posts\/345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=345"}],"version-history":[{"count":6,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/posts\/345\/revisions"}],"predecessor-version":[{"id":352,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/posts\/345\/revisions\/352"}],"wp:attachment":[{"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}