{"id":6749,"date":"2017-06-03T17:33:51","date_gmt":"2017-06-03T09:33:51","guid":{"rendered":"http:\/\/rmohan.com\/?p=6749"},"modified":"2017-06-03T17:33:51","modified_gmt":"2017-06-03T09:33:51","slug":"linux-to-achieve-ssh-password-free-remote-access-server","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6749","title":{"rendered":"Linux to achieve SSH password-free remote access server"},"content":{"rendered":"<p><strong>Linux to achieve SSH password-free remote access server<\/strong><\/p>\n<p>Description<\/p>\n<p>Usually use SSH login remote server, you need to use the input password, hoping to achieve through the key login and exemption from the input password,<br \/>\nwhich can be achieved for the future batch automatic deployment of the host to prepare.<\/p>\n<p>The environment is as follows:<\/p>\n<p>IP address\toperating system<br \/>\nService-Terminal\t192.168.1.10\/24\tCentOS 6.5 x86<br \/>\nClient\t192.168.1.129\/24\tUbuntu 16.04 x86<\/p>\n<p>1. The client generates a key pair<\/p>\n<p>Generate key pair:<\/p>\n<p>rmohan@rmohan:~$ ssh-keygen -t rsa -b 2048<br \/>\nGenerating public\/private rsa key pair.<br \/>\nEnter file in which to save the key (\/home\/rmohan\/.ssh\/id_rsa):<br \/>\nCreated directory &#8216;\/home\/rmohan\/.ssh&#8217;.<br \/>\nEnter passphrase (empty for no passphrase):<br \/>\nEnter same passphrase again:<br \/>\nYour identification has been saved in \/home\/rmohan\/.ssh\/id_rsa.<br \/>\nYour public key has been saved in \/home\/rmohan\/.ssh\/id_rsa.pub.<br \/>\nThe key fingerprint is:<br \/>\nSHA256:eLssyXJLzUCfSN5mu6nqNH9dB\/gOyXSvWBwQdNssIYE rmohan@rmohan<br \/>\nThe key&#8217;s randomart image is:<br \/>\n+&#8212;[RSA 2048]&#8212;-+<br \/>\n|         o=oo    |<br \/>\n|        E .o =   |<br \/>\n|      o    oo o  |<br \/>\n|     + = .o +.   |<br \/>\n|      = So = +   |<br \/>\n|       B o+ = o  |<br \/>\n|    o&#8230;=. * o   |<br \/>\n|   ..+=..+o o    |<br \/>\n|   .o++==        |<br \/>\n+&#8212;-[SHA256]&#8212;&#8211;+<br \/>\nView the generated key pair:<\/p>\n<p>Linuxidc @ rmohan: ~ $ ls .ssh<br \/>\nid_rsa id_rsa.pub <\/p>\n<p># id_rsa for the private key, this generally need to keep confidential; id_rsa.pub for the public key, this can be made public.<\/p>\n<p>2. Upload the public key to the server<\/p>\n<p>    Use the scp command to:<\/p>\n<p>rmohan@rmohan:~$ scp .ssh\/id_rsa.pub root@192.168.1.129:\/root<br \/>\nThe authenticity of host &#8216;192.168.1.129(192.168.1.129)&#8217; can&#8217;t be established.<br \/>\nRSA key fingerprint is SHA256:0Tpm11wruaQXyvOfEB1maIkEwxmjT2AklWb198Vrln0.<br \/>\nAre you sure you want to continue connecting (yes\/no)? yes<br \/>\nWarning: Permanently added &#8216;10.0.0.128&#8217; (RSA) to the list of known hosts.<br \/>\nroot@10.0.0.128&#8217;s password:<br \/>\nid_rsa.pub                                                    100%  393     0.4KB\/s   00:00<br \/>\n3. Server-side operation <\/p>\n<p>    Add the public key from the client to .ssh \/ authorized_keys:<\/p>\n<p>[root@rmohan ~]# cat id_rsa.pub >> .ssh\/authorized_keys<br \/>\n[root@rmohan ~]# chmod 600 .ssh\/authorized_keys<\/p>\n<p># authorized_keys 600<br \/>\n    Modify the ssh configuration file \/etc\/ssh\/sshd_config, find the following line:<\/p>\n<p>PubkeyAuthentication no<br \/>\n    change into:<\/p>\n<p>PubkeyAuthentication yes<br \/>\n4. Test <\/p>\n<p>    Log on to the server using the key on the client:<\/p>\n<p>rmohan@rmohan:~$ ssh -i .ssh\/id_rsa root@192.168.1.129<br \/>\nLast login: Tue May  9 15:14:01 2017 from 192.168.1.129<\/p>\n<p>[root@rmohan ~]#<br \/>\n5. Precautions<br \/>\nIn the server side need to turn off selinux, or finally can not use the key for remote login;<br \/>\nThe client uses the scp command, the server also need to install ssh client, or can not upload the public key to the server side,<br \/>\nyou can also use ssh-copy-id root@192.168.1.129 instead of scp operation (so that the server Do not need to perform the operation. Ssh directory and other operations, that is equivalent to the order can help us complete the key upload and configuration work);<br \/>\nThe following article on SSH related you may also like, may wish to refer to the following:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux to achieve SSH password-free remote access server<\/p>\n<p>Description<\/p>\n<p>Usually use SSH login remote server, you need to use the input password, hoping to achieve through the key login and exemption from the input password, which can be achieved for the future batch automatic deployment of the host to prepare.<\/p>\n<p>The environment is as follows:<\/p>\n<p> [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6749"}],"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=6749"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6749\/revisions"}],"predecessor-version":[{"id":6750,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6749\/revisions\/6750"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}