{"id":623,"date":"2019-09-06T23:27:06","date_gmt":"2019-09-06T22:27:06","guid":{"rendered":"https:\/\/notiz.comanet.xyz\/?p=623"},"modified":"2019-09-06T23:27:06","modified_gmt":"2019-09-06T22:27:06","slug":"ssh-login-without-password-using-ssh-keygen-ssh-copy-id","status":"publish","type":"post","link":"https:\/\/notiz.comanet.xyz\/?p=623","title":{"rendered":"SSH Login Without Password Using ssh-keygen &#038; ssh-copy-id"},"content":{"rendered":"\n<p>You can login to a remote Linux server without entering password in 3\n simple steps using ssky-keygen and ssh-copy-id as explained in this \narticle.<br>\n<br>\n<strong> ssh-keygen<\/strong> creates the public and private keys.<strong> ssh-copy-id<\/strong>\n copies the local-host\u2019s public key to the remote-host\u2019s authorized_keys\n file. ssh-copy-id also assigns proper permission to the remote-host\u2019s \nhome, ~\/.ssh, and ~\/.ssh\/authorized_keys.<br>\n<br>\nThis article also explains 3 minor annoyances of using ssh-copy-id and how to use ssh-copy-id along with ssh-agent.<br>\n<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create public and private keys using ssh-key-gen on local-host<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">jsmith@local-host$ [Note: You are on local-host here]\n\njsmith@local-host$ <strong>ssh-keygen\n<\/strong>Generating public\/private rsa key pair.\nEnter file in which to save the key (\/home\/jsmith\/.ssh\/id_rsa):[Enter key]\nEnter passphrase (empty for no passphrase): [Press enter key]\nEnter same passphrase again: [Pess enter key]\nYour identification has been saved in \/home\/jsmith\/.ssh\/id_rsa.\nYour public key has been saved in \/home\/jsmith\/.ssh\/id_rsa.pub.\nThe key fingerprint is:\n33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9 jsmith@local-host<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Copy the public key to remote-host using ssh-copy-id<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">jsmith@local-host$ <strong>ssh-copy-id -i ~\/.ssh\/id_rsa.pub remote-host<\/strong>\njsmith@remote-host's password:\nNow try logging into the machine, with \"ssh 'remote-host'\", and check in:\n\n.ssh\/authorized_keys\n\nto make sure we haven't added extra keys that you weren't expecting.<\/pre>\n\n\n\n<p><strong>Note:<\/strong> ssh-copy-id <strong>appends<\/strong> the keys to the remote-host\u2019s .ssh\/authorized_key.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Login to remote-host without entering the password<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">jsmith@local-host$ <strong>ssh remote-host<\/strong>\nLast login: Sun Nov 16 17:22:33 2008 from 192.168.1.2\n[Note: SSH did not ask for password.]\n\njsmith@remote-host$ [Note: You are on remote-host here]<\/pre>\n\n\n\n<p><br>\nThe above 3 simple steps should get the job done in most cases.<br>\n<br>\nWe also discussed earlier in detail about performing SSH and SCP from <a href=\"https:\/\/www.thegeekstuff.com\/2008\/06\/perform-ssh-and-scp-without-entering-password-on-openssh\/\">openSSH to openSSH<\/a> without entering password.<br>\n<br>\nIf you are using SSH2, we discussed earlier about performing SSH and SCP without password from <a href=\"https:\/\/www.thegeekstuff.com\/2008\/06\/comprehensive-guide-for-ssh2-key-based-authentication-setup\/\">SSH2 to SSH2<\/a> , from <a href=\"https:\/\/www.thegeekstuff.com\/2008\/07\/ssh-key-based-authentication-setup-from-openssh-to-ssh2\/\">OpenSSH to SSH2<\/a> and from <a href=\"https:\/\/www.thegeekstuff.com\/2008\/10\/perform-ssh-and-scp-without-password-from-ssh2-to-openssh\/\">SSH2 to OpenSSH<\/a>.<br>\n<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using ssh-copy-id along with the ssh-add\/ssh-agent<\/h3>\n\n\n\n<p>When no value is passed for the <em>option -i<\/em> and If <em>~\/.ssh\/identity.pub<\/em> is not available, <em>ssh-copy-id<\/em> will display the following error message.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">jsmith@local-host$ ssh-copy-id -i remote-host\n\/usr\/bin\/ssh-copy-id: ERROR: No identities found<\/pre>\n\n\n\n<p><br>\nIf you have loaded keys to the <em>ssh-agent<\/em> using the <em>ssh-add<\/em>, then <em>ssh-copy-id<\/em> will get the keys from the <em>ssh-agent<\/em> to copy to the remote-host. i.e, it copies the keys provided by <strong><em>ssh-add -L<\/em><\/strong> command to the remote-host, when you don\u2019t pass <em>option -i<\/em> to the <em>ssh-copy-id<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">jsmith@local-host$ <strong>ssh-agent $SHELL\n<\/strong>\njsmith@local-host$ <strong>ssh-add -L<\/strong>\nThe agent has no identities.\n\njsmith@local-host$ <strong>ssh-add<\/strong>\nIdentity added: \/home\/jsmith\/.ssh\/id_rsa (\/home\/jsmith\/.ssh\/id_rsa)\n\njsmith@local-host$ <strong>ssh-add -L<\/strong>\nssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsJIEILxftj8aSxMa3d8t6JvM79DyBV\naHrtPhTYpq7kIEMUNzApnyxsHpH1tQ\/Ow== \/home\/jsmith\/.ssh\/id_rsa\n\njsmith@local-host$ <strong>ssh-copy-id -i remote-host<\/strong>\njsmith@remote-host's password:\nNow try logging into the machine, with \"ssh 'remote-host'\", and check in:\n\n.ssh\/authorized_keys\n\nto make sure we haven't added extra keys that you weren't expecting.\n[Note: This has added the key displayed by ssh-add -L]<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Three Minor Annoyances of ssh-copy-id<\/h3>\n\n\n\n<p>Following are few minor annoyances of the ssh-copy-id.<br>\n<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Default public key:<\/strong> ssh-copy-id uses ~\/.ssh\/identity.pub as the default public key file (i.e when no value is passed to <em>option -i<\/em>).\n Instead, I wish it uses id_dsa.pub, or id_rsa.pub, or identity.pub as \ndefault keys. i.e If any one of them exist, it should copy that to the \nremote-host. If two or three of them exist, it should copy identity.pub \nas default.<\/li><li><strong>The agent has no identities:<\/strong> When the <em>ssh-agent<\/em> is running and the <em>ssh-add -L<\/em>\n returns \u201cThe agent has no identities\u201d (i.e no keys are added to the \nssh-agent), the ssh-copy-id will still copy the message \u201cThe agent has \nno identities\u201d to the remote-host\u2019s authorized_keys entry.<\/li><li><strong>Duplicate entry in authorized_keys:<\/strong> I wish \nssh-copy-id validates duplicate entry on the remote-host\u2019s \nauthorized_keys. If you execute ssh-copy-id multiple times on the \nlocal-host, it will keep appending the same key on the remote-host\u2019s \nauthorized_keys file without checking for duplicates. Even with \nduplicate entries everything works as expected. But, I would like to \nhave my authorized_keys file clutter free.<\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>You can login to a remote Linux server without entering password in 3 simple steps using ssky-keygen and ssh-copy-id as explained in this article. ssh-keygen creates the public and private keys. ssh-copy-id copies the local-host\u2019s public key to the remote-host\u2019s authorized_keys file. ssh-copy-id also assigns proper permission to the remote-host\u2019s home, ~\/.ssh, and ~\/.ssh\/authorized_keys. This&#8230;<\/p>\n","protected":false},"author":1,"featured_media":624,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-623","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/posts\/623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=623"}],"version-history":[{"count":1,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/posts\/623\/revisions"}],"predecessor-version":[{"id":625,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/posts\/623\/revisions\/625"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/media\/624"}],"wp:attachment":[{"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}