{"id":1163,"date":"2018-10-22T17:06:53","date_gmt":"2018-10-22T17:06:53","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=1163"},"modified":"2018-10-23T00:25:26","modified_gmt":"2018-10-23T00:25:26","slug":"how-to-setup-ssh-key-authentication","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/22\/how-to-setup-ssh-key-authentication\/","title":{"rendered":"How To Setup SSH Key Authentication"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxadmin.io\/wp-content\/uploads\/2017\/07\/ssh-key-generation-1.png\" alt=\"SSH Key generation\" width=\"667\" height=\"154\" \/><\/p>\n<p>SSH key authentication can be used for password-less login between 2 servers. This is also useful for adding a key to accounts like git or gitlab for version management.<\/p>\n<h2>Source Server SSH Key Configuration<\/h2>\n<p>Generate a RSA key for this system by typing the following<\/p>\n<p>ssh-keygen -t rsa<\/p>\n<p>The key generated will ask for a location to store the newly created key, the default is the home directory of the user creating it under the .ssh directory. It will also ask you for a password which you optionally leave blank.<\/p>\n<h2>Destination Server SSH Key Configuration<\/h2>\n<p>On the source server you can use ssh-copy-id to copy over the id_rsa.pub file to the new server. It will use the SSH protocol to copy over the public key and insert it into the authorized_keys file on the destination server. To read more about ssh-copy-id you can read the <a href=\"https:\/\/linux.die.net\/man\/1\/ssh-copy-id\">man page<\/a>.<\/p>\n<p>ssh-copy-id -i ~\/.ssh\/id_rsa.pub <a href=\"\/cdn-cgi\/l\/email-protection\">[email protected]<\/a>Replacing 192.168.1.3 with the appropriate host name of the destination server and user with the user you would like to add the key too.<\/p>\n<p>\/bin\/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed<br \/>\n\/bin\/ssh-copy-id: INFO: 1 key(s) remain to be installed &#8212; if you are prompted now it is to install the new keys<br \/>\n<a href=\"\/cdn-cgi\/l\/email-protection\">[email protected]<\/a>&#8216;s password:<\/p>\n<p>Number of key(s) added: 1<\/p>\n<p>Now try logging into the machine, with: &#8220;ssh &#8216;<a href=\"\/cdn-cgi\/l\/email-protection\">[email protected]<\/a>&#8216;&#8221;<br \/>\nand check to make sure that only the key(s) you wanted were added.<\/p>\n<h2>Manual SSH Key Configuration on the Destination Server<\/h2>\n<p>First verify if you already have a .ssh directory<\/p>\n<p>ls ~\/.ssh<\/p>\n<p>If you do not you will want to create the following directory<\/p>\n<p>mkdir ~\/.ssh<\/p>\n<p>You will also want to create authorized_keys file<\/p>\n<p>touch ~\/.ssh\/authorized_keys<\/p>\n<p>You will then want to copy the public key from the source server in to the authorized_keys file. You can do this by copying the id_rsa.pub on the source server.<\/p>\n<p>scp ~\/.ssh\/id_rsa.pub <a href=\"\/cdn-cgi\/l\/email-protection\">[email protected]<\/a>_host:~\/.ssh\/authorized_keys<\/p>\n<h2>Root SSH Key Configuration<\/h2>\n<p>If you are adding keys to a root user on the destination server, you will want to ensure the sshd configuration allows remote root logins with either the following 2 options enabled in \/etc\/ssh\/sshd_config<\/p>\n<p>PermitRootLogin yes<\/p>\n<p>Which will allow root logins with both passwords and keys.<\/p>\n<p>PermitRootLogin without-password<\/p>\n<p>Which will allow root logins only with keys<\/p>\n<p>If you modify the ssh configuration, you will need to reload sshd to load the new configuration<\/p>\n<p>\/etc\/init.d\/sshd reload<\/p>\n<p>After you have added the key to the destination server, ssh from the source server it should allow you to login using the key.<\/p>\n<p>Jul 4, 2017LinuxAdmin.io<\/p>\n<p><a href=\"https:\/\/linuxadmin.io\/setup-ssh-key-authentication\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SSH key authentication can be used for password-less login between 2 servers. This is also useful for adding a key to accounts like git or gitlab for version management. Source Server SSH Key Configuration Generate a RSA key for this system by typing the following ssh-keygen -t rsa The key generated will ask for a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/22\/how-to-setup-ssh-key-authentication\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How To Setup SSH Key Authentication&#8221;<\/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-1163","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=1163"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1163\/revisions"}],"predecessor-version":[{"id":1280,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1163\/revisions\/1280"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=1163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=1163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=1163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}