{"id":162,"date":"2016-06-26T11:46:09","date_gmt":"2016-06-26T03:46:09","guid":{"rendered":"http:\/\/pony.hk\/?p=162"},"modified":"2022-12-08T08:12:46","modified_gmt":"2022-12-08T00:12:46","slug":"ssh%e5%bb%ba%e7%ab%8b%e4%bf%a1%e4%bb%bb%e5%85%b3%e7%b3%bb","status":"publish","type":"post","link":"https:\/\/lnmp.ivan.xin\/?p=162","title":{"rendered":"SSH\u5efa\u7acb\u4fe1\u4efb\u5173\u7cfb"},"content":{"rendered":"<p>A\u673a\u5668\u4e0d\u7528\u5bc6\u7801\u76f4\u63a5ssh\u767b\u9646B\u673a\u5668\uff1a<\/p>\n<p>1\u3001\u5728B\u673a\u5668\u4e0a\uff0c\u751f\u6210B\u673a\u5668\u7684\u516c\u79c1\u94a5\u5319\u5bf9\uff0c\u7528\u8fd9\u6761\u547d\u4ee4\u751f\u6210\uff1assh-keygen -b 1024 -t rsa<\/p>\n<p>[root@localhost ~]# ssh-keygen -b 1024 -t rsa<br \/>\nGenerating public\/private rsa key pair.<br \/>\nEnter file in which to save the key (\/root\/.ssh\/id_rsa):<br \/>\nEnter passphrase (empty for no passphrase):<br \/>\nEnter same passphrase again:<br \/>\nYour identification has been saved in \/root\/.ssh\/id_rsa.<br \/>\nYour public key has been saved in \/root\/.ssh\/id_rsa.pub.<br \/>\nThe key fingerprint is:<br \/>\n40:44:8d:2c:20:bd:c0:1b:b2:01:9f:e8:f9:bb:db:67 root@localhost.localdomain<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u516c\u94a5\u548c\u79c1\u94a5\u90fd\u751f\u6210\u5728\u4e86.ssh\u76ee\u5f55\u4e0b\uff0c\u516c\u94a5\u4e3aid_rsa.pub\uff0c\u79c1\u94a5\u4e3aid_rsa<br \/>\n\u91cd\u547d\u540d\u8fd9\u4e24\u4e2a\u6587\u4ef6\uff0c\u628a\u516c\u94a5\u5185\u5bb9\u5199\u5165authorized_keys\u6587\u4ef6\u4e2d<br \/>\n[root@localhost ~] cd .ssh<br \/>\n[root@localhost .ssh]# mv id_rsa.pub id_rsa_B_root.pub<br \/>\n[root@localhost .ssh]# mv id_rsa id_rsa_B_root<br \/>\n[root@localhost .ssh]# cat id_rsa_B_root.pub &gt;&gt; authorized_keys<\/p>\n<p>2\u3001\u62f7\u8d1dB\u673a\u5668\u7684\u79c1\u94a5\u5230A\u673a\u5668\u7684.ssh\u76ee\u5f55\uff08\u6ca1\u6709.ssh\u76ee\u5f55\u7684\u8bdd\uff0c\u624b\u52a8\u5efa\u7acb\uff09<br \/>\n\u7528\u8fd9\u4e2a\u547d\u4ee4\uff1ascp ~\/.ssh\/id_rsa_B_root root@A\u673a\u5668IP:~\/.ssh\/<br \/>\n\u5b8c\u6210\u62f7\u8d1d<\/p>\n<p>3\u3001\u767b\u5f55A\u673a\u5668\uff0c\u5728.ssh\u76ee\u5f55\u4e0b\u5efa\u7acbconfig\u6587\u4ef6\uff0c\u8fdb\u884c\u914d\u7f6e\u3002<br \/>\n[root@localhost .ssh]# vi config \u5185\u5bb9\u5982\u4e0b\uff1a<br \/>\nHost B<br \/>\nHostname 6.6.6.6<br \/>\nUser root<br \/>\nPort 22<br \/>\nIdentityFile ~\/.ssh\/id_rsa_B_root<\/p>\n<p>4\u3001\u5728A\u673a\u4e0a\u4fee\u6539\u8fd9\u4e24\u4e2a\u6587\u4ef6\u7684\u6743\u9650<br \/>\n[root@localhost .ssh]# chmod 600 config<br \/>\n[root@localhost .ssh]# chmod 600 id_rsa_B_root<\/p>\n<p>\u641e\u5b9a\uff01\u8fd9\u6837\u5c31\u53ef\u4ee5\u62ff\u7740B\u673a\u7684\u79c1\u94a5id_rsa_B_root\u653e\u5230\u5176\u4ed6\u4efb\u4f55\u673a\u5668\u4e0a\uff0c\u514d\u5bc6\u7801\u767b\u5f55B\u673a\u4e86\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>============<\/p>\n<p>\u5982\u679c\u6267\u884c\u4ee5\u4e0a\u64cd\u4f5c\u540e\uff0c\u767b\u9646\u8fd8\u662f\u9700\u8981\u5bc6\u7801\uff0c\u5e94\u8be5\u5c31\u662f\u6743\u9650\u7684\u95ee\u9898\u4e86\u3002\u505a\u5982\u4e0b\u5c1d\u8bd5\uff1a<\/p>\n<p>A\u673a\uff1a<br \/>\nchmod 700 ~\/.ssh\/<br \/>\nchmod 600 ~\/.ssh\/id_rsa_B_root<br \/>\nssh-agent bash<br \/>\nssh-add ~\/.ssh\/id_rsa_B_root<\/p>\n<p>B\u673a\uff1a<br \/>\nchmod 700 ~\/.ssh\/<br \/>\nchmod 600 ~\/.ssh\/authorized_keys<br \/>\n\u7528root\u7528\u6237\u91cd\u542fsshd\u8fdb\u7a0b<\/p>\n<p>\u8fd8\u6709\u4e00\u4e2a\u9700\u8981\u6ce8\u610f\u7684\u5730\u65b9\uff0c~\/.ssh\/config\u6587\u4ef6\u4e2d\uff0cHostname\u662f\u57df\u540d\u6216\u8005IP\u5730\u5740\uff0cHost\u662f\u4e3b\u673a\u540d\uff0c\u5efa\u8baeHost\u6216\u8005Hostname\u53ea\u5199\u4e00\u4e2a\uff0c\u56e0\u4e3a\u4e24\u4e2a\u90fd\u5199\u7684\u8bdd\uff0c\u53ef\u80fd\u9020\u6210\u514d\u5bc6\u5931\u8d25\uff0c\u6709\u4ee5\u4e0b\u4e09\u79cd\u60c5\u51b5\uff1a<br \/>\n1, \u5982\u679c\u4e24\u4e2a\u90fd\u5199\u7684\u8bdd\uff0cssh root@B\u662f\u53ef\u4ee5\u514d\u5bc6\u767b\u9646\u7684\uff0c\u4f46\u662fssh root@6.6.6.6\u5c31\u9700\u8981\u8f93\u5165\u5bc6\u7801\u3002\u539f\u56e0\uff1a\u7f51\u7edc\u67e5\u8be2\u6709\u8fd9\u6837\u7684\u89e3\u91ca\u201c.ssh\/config\u6587\u4ef6\u673a\u5236\uff0c\u8be5\u547d\u4ee4ssh name@host\u9996\u5148\u5339\u914dhost\u4e2d\u7684Host\u5b57\u6bb5.ssh\/config\uff0c\u800c\u4e0d\u662fHostName\u5b50\u5b57\u6bb5\u3002\u8fd9\u8ba9\u6211\u56f0\u60d1\u4e86\u597d\u51e0\u4e2a\u661f\u671f......\u201d<br \/>\n2, \u5982\u679c\u53ea\u5199Host\u4e0d\u5199Hostname\uff0c\u9700\u8981\u5728\/etc\/hosts\u6587\u4ef6\u4e2d\u914d\u7f6eB\u7684IP\u5730\u5740<br \/>\n3, \u5982\u679c\u4e0d\u5199Host\u53ea\u5199Hostname\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528ssh root@6.6.6.6\u514d\u5bc6\u767b\u9646<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A\u673a\u5668\u4e0d\u7528\u5bc6\u7801\u76f4\u63a5ssh\u767b\u9646B\u673a\u5668\uff1a 1\u3001\u5728B\u673a\u5668\u4e0a\uff0c\u751f\u6210B\u673a\u5668\u7684\u516c\u79c1\u94a5\u5319\u5bf9\uff0c\u7528\u8fd9\u6761\u547d\u4ee4\u751f\u6210\uff1assh-keyg...<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-162","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=\/wp\/v2\/posts\/162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=162"}],"version-history":[{"count":8,"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=\/wp\/v2\/posts\/162\/revisions"}],"predecessor-version":[{"id":732,"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=\/wp\/v2\/posts\/162\/revisions\/732"}],"wp:attachment":[{"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}