{"id":1671,"date":"2012-11-05T12:19:03","date_gmt":"2012-11-05T04:19:03","guid":{"rendered":"http:\/\/rmohan.com\/?p=1671"},"modified":"2012-11-05T14:44:12","modified_gmt":"2012-11-05T06:44:12","slug":"ssh-login-without-password","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=1671","title":{"rendered":"SSH login without password"},"content":{"rendered":"<p>we\u00a0 need an <strong>automatic<\/strong> login from host A \/ user a to Host B \/ user b. You don&#8217;t want to enter any passwords, because you want to call <tt>ssh<\/tt>from a within a shell script.<\/p>\n<h2>How to do it<\/h2>\n<p>First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:<\/p>\n<pre>a@A:~&gt; ssh-keygen -t rsa\r\nGenerating public\/private rsa key pair.\r\nEnter file in which to save the key (\/home\/a\/.ssh\/id_rsa): \r\nCreated directory '\/home\/a\/.ssh'.\r\nEnter passphrase (empty for no passphrase): \r\nEnter same passphrase again: \r\nYour identification has been saved in \/home\/a\/.ssh\/id_rsa.\r\nYour public key has been saved in \/home\/a\/.ssh\/id_rsa.pub.\r\nThe key fingerprint is:\r\n3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A\r\n<\/pre>\n<p>Now use <tt>ssh<\/tt> to create a directory <tt>~\/.ssh<\/tt> as user b on B. (The directory may already exist, which is fine):<\/p>\n<pre>a@A:~&gt; ssh b@B mkdir -p .ssh\r\nb@B's password: \r\n<\/pre>\n<p>Finally append a&#8217;s new public key to <tt>b@B:.ssh\/authorized_keys<\/tt> and enter b&#8217;s password one last time:<\/p>\n<pre>a@A:~&gt; cat .ssh\/id_rsa.pub | ssh b@B 'cat &gt;&gt; .ssh\/authorized_keys'\r\nb@B's password: \r\n<\/pre>\n<p>From now on you can log into B as b from A as a without password:<\/p>\n<pre>a@A:~&gt; ssh b@B hostname\r\nB\r\n<\/pre>\n<p><strong>A note<\/strong> from one of our readers: Depending on your version of SSH you might also have to do the following changes:<\/p>\n<ul>\n<li>Put the public key in <tt>.ssh\/authorized_keys2<\/tt><\/li>\n<li>Change the permissions of <tt>.ssh<\/tt> to <tt>700<\/tt><\/li>\n<li>Change the permissions of <tt>.ssh\/authorized_keys2<\/tt> to <tt>640<\/tt><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>we need an automatic login from host A \/ user a to Host B \/ user b. You don&#8217;t want to enter any passwords, because you want to call sshfrom a within a shell script.<\/p>\n<p> How to do it <\/p>\n<p>First log in on A as user a and generate a pair of authentication keys. Do [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1671"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1671"}],"version-history":[{"count":4,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1671\/revisions"}],"predecessor-version":[{"id":1674,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1671\/revisions\/1674"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}