{"id":2374,"date":"2021-12-19T19:44:22","date_gmt":"2021-12-19T11:44:22","guid":{"rendered":"http:\/\/blog.zengqq.com.cn\/?p=2374"},"modified":"2022-09-11T14:15:52","modified_gmt":"2022-09-11T06:15:52","slug":"%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e4%b9%8bssh%e5%8a%a0%e5%af%86%e5%85%ac%e9%92%a5%e6%b7%bb%e5%8a%a0","status":"publish","type":"post","link":"https:\/\/blog.zengqq.com.cn\/?p=2374","title":{"rendered":"\u7f51\u7edc\u5b89\u5168\u4e4bSSH\u52a0\u5bc6\u516c\u94a5\u6dfb\u52a0"},"content":{"rendered":"\n<p>\u4e00\u822c\u9700\u8981\u67e5\u9605\u8fd9\u7bc7\u9760RSA\u641c\u7d20\u51fa\u6765\u7684\u5de5\u5177\u6587\u7ae0\u7684\u65f6\u5019\uff0c\u5c31\u662f\u6211\u9700\u8981\u6dfb\u52a0\u516c\u94a5\u6765\u514d\u5bc6shh\u8bbf\u95ee\u6216\u8005scp\/sftp\/sycn\u4f20\u8f93\u6587\u4ef6\u7684\u65f6\u5019\u3002\u7b80\u5355\u5217\u51fa\u91cd\u70b9\u4ee5\u65b9\u4fbf\u67e5\u9605\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5047\u8bbe\u8bbf\u95ee\u53d1\u8d77\u65b9\u4e3aA\uff0c\u88ab\u8bbf\u95ee\u5bf9\u8c61\u4e3aB\uff0c\u8c01\u9700\u8981keygen\uff1f\u7b54\u6848\uff1aA\u9700\u8981\u751f\u6210\u4e24\u4e2a\u5bc6\u94a5\uff0c\u4e00\u4e2a\u79c1\uff0c\u4e00\u4e2a\u516c\u3002<\/li><li>\u88ab\u8bbf\u95ee\u5bf9\u8c61B\u5982\u4f55\u6dfb\u52a0A\u6240\u7ed9\u7684\u516c\u94a5id_rsa.pub\uff1f\u7b54\u6848\uff1a\u6dfb\u52a0\u5230B\u7684\u9690\u85cfssh\u76ee\u5f55\uff0c~\/.ssh\u4e0b<\/li><li>\u5982\u4f55\u6839\u636e\u590d\u6742\u7a0b\u5ea6\u6765\u51b3\u5b9assh\u7684\u8bbf\u95ee\u53d1\u8d77\u65b9\uff1f<\/li><\/ul>\n\n\n\n<p>\u5199\u8fd9\u6837\u4e00\u7bc7\u7684\u7f18\u7531\u662f\u56e0\u4e3a\u6211\u9047\u5230\u4e4b\u524d\u61f5\u61c2\u641e\u4e0d\u6e05\u695a\u7684\u95ee\u9898\uff0c\u5728\u6dfb\u52a0\u5b8c\u516c\u94a5\u540e\u5374\u4e0d\u80fd\u514d\u5bc6ssh\u3001sftp\u3001rsync -P\uff0c\u7528ssh -vvv\u6765debug\u770b\u5230\u4e86\u7cfb\u7edf\u8fd8\u662f\u81ea\u52a8\u5faa\u4f8bid_rsa.pub\u800c\u4e0d\u662f\u53bb\u627embp1_rsa.pub<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">debug2: ssh_connect_direct\ndebug1: Connecting to 192.168.1.189 [192.168.1.189] port 22.\ndebug1: Connection established.\ndebug1: identity file \/Users\/qingqizeng\/.ssh\/id_rsa type -1\ndebug1: identity file \/Users\/qingqizeng\/.ssh\/id_rsa-cert type -1\ndebug1: identity file \/Users\/qingqizeng\/.ssh\/id_dsa type -1\ndebug1: identity file \/Users\/qingqizeng\/.ssh\/id_dsa-cert type -1\ndebug1: identity file \/Users\/qingqizeng\/.ssh\/id_ecdsa type -1\ndebug1: identity file \/Users\/qingqizeng\/.ssh\/id_ecdsa-cert type -1\ndebug1: identity file \/Users\/qingqizeng\/.ssh\/id_ed25519 type -1\ndebug1: identity file \/Users\/qingqizeng\/.ssh\/id_ed25519-cert type -1\ndebug1: identity file \/Users\/qingqizeng\/.ssh\/id_xmss type -1\ndebug1: identity file \/Users\/qingqizeng\/.ssh\/id_xmss-cert type -1<\/pre>\n\n\n\n<p>\u8fd9\u5c31\u8ba9\u6211\u8499\u4e86\uff0c\u4e3a\u4ec0\u4e48\u6dfb\u52a0\u4e86\u516c\u94a5\u8fd8\u662f\u4e0d\u80fd\u514d\u5bc6ssh\u5462\uff1f\u539f\u6765\u6211\u9519\u8bef\u7684\u7406\u89e3\u4e86id_rsa.pub\u8fd9\u4e2a\u540d\u5b57\u7684\u7528\u610f\u3002\u6dfb\u52a0\u516c\u94a5\u7684\u65b9\u6cd5\u662f\u628a\u65e0\u8bba\u4ec0\u4e48key\u90fdcat  xxx.key  &gt;&gt;  authorized_keys \u91cc\u9762\uff0c\u56e0\u4e3a\u8fd9\u6837authorized_keys\u91cc\u9762\u5c31\u6709\u4e86 xxx.key\u7684\u5185\u5bb9\u3002\u4f60\u95ee\u6211\u662f\u600e\u4e48\u77e5\u9053\u7684\uff0c\u6211\u544a\u8bc9\u4f60\uff0c\u6211vim\u4e86authorized_keys\u4ee5\u4e0b\uff0c\u770b\u5230\u4e86\u5927\u81f4\u7684\u5185\u5bb9,\u4ece\u4e0b\u9762\u7684\u56fe\u4e2d\u4f60\u53ef\u4ee5\u770b\u5230\u4e24\u4e2a\u52a0\u5bc6\u516c\u94a5\u7684\u201c\u6307\u7eb9\u201d\uff1a<img loading=\"lazy\" decoding=\"async\" width=\"480\" height=\"164\" class=\"wp-image-2375\" style=\"width: 480px;\" src=\"https:\/\/blog.zengqq.com.cn\/wp-content\/uploads\/2021\/12\/\u622a\u5c4f2021-12-19-\u4e0b\u53487.26.25.png\" alt=\"ssh-rsa\" srcset=\"https:\/\/blog.zengqq.com.cn\/wp-content\/uploads\/2021\/12\/\u622a\u5c4f2021-12-19-\u4e0b\u53487.26.25.png 881w, https:\/\/blog.zengqq.com.cn\/wp-content\/uploads\/2021\/12\/\u622a\u5c4f2021-12-19-\u4e0b\u53487.26.25-480x164.png 480w, https:\/\/blog.zengqq.com.cn\/wp-content\/uploads\/2021\/12\/\u622a\u5c4f2021-12-19-\u4e0b\u53487.26.25-768x262.png 768w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/p>\n\n\n\n<p>\u6240\u4ee5\u5728\u6dfb\u52a0\u516c\u94a5\u7684\u670d\u52a1\u5668\u7684~\/.ssh\u76ee\u5f55\u4e0b\uff0cid_rsa.pub\u53ea\u662f\u4e00\u4e2a\u201c\u4ee3\u6570\u201d\u6216\u8005\u8bf4\u662f\u4e00\u4e2a\u201c\u8fc7\u5ba2\u201d\uff0c\u5f53\u8ffd\u52a0\u201ccat\u201d\u5b8cauthorized keys\u4e4b\u540e\uff0c\u5b83\u5c31\u6ca1\u6709\u7528\u4e86\u3002\u7cfb\u7edf\u4e0d\u4f1a\u6839\u636e\u4f60\u7ed9xxx_rsa.pub\u8d77\u4e00\u4e2a\u4ec0\u4e48\u540d\u5b57\uff0c\u5c31\u53bb\u5bf9\u5e94\u627exxx_rsa\u53bb\u89e3\u5bc6\uff0c\u800c\u662f\u4f1a\u5728\u63a5\u901assh\u540e\u94fe\u63a5\u5230\u672c\u5730\u7684~\/.ssh\u4e0b\u53bb\u7167\u65e7\u5bfb\u627eid_rsa\uff0c\u8fd9\u6837authorized key\u516c\u94a5\u7684\u201c\u6307\u7eb9\u201d\u914d\u4e0a\u672c\u5730id_rsa\u5c31\u89e3\u5bc6\u6210\u529f\u4e86\u3002\u4e4b\u524d\u6211\u4e00\u76f4\u4ee5\u4e3a~\/.ssh\u9700\u8981\u5b58\u50a8\u6240\u6709\u7684\u516c\u94a5\uff0c\u6240\u4ee5\u9700\u8981\u4fdd\u5b58id1_rsa.pub;id2_rsa.pub;id3_rsa.pub;&#8230;..idN_rsa.pub \u73b0\u5728\u770b\u6765\u662f\u6211\u60f3\u9519\u4e86\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#\u7b2c\u4e00\u6b65\uff1a\u672c\u5730\u9e21\u751f\u6210id_rsa.pub,\u8f93\u5165\u6307\u4ee4\u4e00\u8def\u56de\u8f66\uff0c\u4e0d\u8981\u60f3\u592a\u591a\n\u672c\u5730\u9e21$ ssh-keygen -t rsa\nGenerating public\/private rsa key pair.\nEnter file in which to save the key (\/Users\/qxxxxxzeng\/.ssh\/id_rsa): \nEnter passphrase (empty for no passphrase): \nEnter same passphrase again: \nYour identification has been saved in \/Users\/qxxxxxzeng\/.ssh\/id_rsa.\nYour public key has been saved in \/Users\/qxxxxxzeng\/.ssh\/id_rsa.pub.\nThe key fingerprint is:\nSHA256:qJmWKqbhGQSpyrQtntfMLK5ExiixuJczILIly1T6RWU qxxxxxzeng@MBP\nThe key's randomart image is:\n+---[RSA 3072]----+\n|       E         |\n| .    o          |\n|+  . .           |\n|*oo .  .         |\n|@O.  .. S        |\n|&amp;B+..=           |\n|*B=o@            |\n|=+=B =           |\n|+B=..            |\n+----[SHA256]-----+\n\u672c\u5730\u9e21$ \n \n#\u7b2c\u4e8c\u6b65\uff1a\u672c\u5730\u9e21scp\u516c\u94a5\u5230\u8fdc\u7aef\u7684usr@ip:~\/.ssh\u76ee\u5f55\u4e0b,\u8bb0\u5f97\u8f93\u5165ssh\u7684\u5bc6\u7801\n\u672c\u5730\u9e21$ scp id_rsa.pub QQ@192.168.1.189:~\/.ssh\n\u672c\u5730\u9e21$ QQ@192.168.1.189's password: \n\u672c\u5730\u9e21$ id_rsa.pub                                    100%  568    10.3KB\/s   00:00 \n\n#\u7b2c\u4e09\u6b65\uff1a\u8fdc\u7aef\u670d\u52a1\u5668\u4e0b\uff0c\u7528[cat]\u8ffd\u52a0~\/.ssh\/id_rsa.pub \u5230authorized_keys\ncat ~\/.ssh\/id_rsa.pub >> ~\/.ssh\/authorized_keys\n#\u5982\u679c\u4f60\u95f2\u7740\u6ca1\u4e8b\uff0c\u5e76\u4e14\u63a5\u7684\u4e4b\u524dauthorized_keys\u7684\u5185\u5bb9\uff0c\u4f60\u53ef\u4ee5\u770b\u770bcat\u4e4b\u540e\u662f\u4e0d\u662f\u591a\u4e86\u4e00\u4e2a\u672c\u5730\u9e21\u7684\u6307\u7eb9\n#\u672c\u5730\u9e21$ vim ~\/.ssh\/authorized_keys\n\n\n#\u7b2c\u56db\u90e8\uff1a\u5728\u672c\u5730\u9e21\u4e2d\u7528ssh\u9a8c\u8bc1\u514d\u5bc6\uff0c\u672c\u5730\u9e21\u662f192.168.1.156\n\u672c\u5730\u9e21$ ssh -vvv QQ@192.168.1.189\nOpenSSH_8.1p1, LibreSSL 2.7.3\ndebug1: Reading configuration data \/etc\/ssh\/ssh_config\ndebug1: \/etc\/ssh\/ssh_config line 47: Applying options for *\ndebug2: resolve_canonicalize: hostname 192.168.1.189 is address\ndebug2: ssh_connect_direct\ndebug1: Connecting to 192.168.1.189 [192.168.1.189] port 22.\ndebug1: Connection established.\n<\/pre>\n\n\n\n<p>\u81ea\u6b64\uff0c\u4f60\u5df2\u7ecf\u770b\u5230connection established\uff0c\u94fe\u63a5\u6210\u529f\u4e86<\/p>\n\n\n\n<p>\u91cd\u7f6essh\u7684key<\/p>\n\n\n\n<p>\u4e00\u822c\u770b\u5230\u8fd9\u91cc\uff0c\u4f60\u5c31\u5df2\u7ecf\u4e0d\u662f\u7b2c\u4e00\u6b21\u8bbe\u7f6essh\u7684id_rsa.pub\u7684key\uff0c\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff1a<strong>\u5982\u679c\u672c\u5730\u670d\u52a1\u5668A\uff0c\u5b83\u5728\u4f60\u8fdc\u7aef\u670d\u52a1\u5668B\u91cd\u7f6e\u524d\u5c31\u5df2\u7ecfssh\u6210\u529f\u8bbf\u95ee\u8fc7\u65e7\u7684\u8fdc\u7aef\u670d\u52a1\u5668B<\/strong>\uff0c\u90a3\u4e48<strong>\u672c\u5730A\u7684knownhost\u5c31\u4f1a\u5b58\u50a8\u4e4b\u524d\u7248\u672c\u7684\u8fdc\u7a0b\u670d\u52a1B\u7684ip\u5730\u5740<\/strong>\uff0c\u73b0\u5728\u5c31\u6709\u4e2a\u95ee\u9898\u4e86\uff0c\u5bf9\u4e8e\u672c\u5730\u670d\u52a1\u5668A\uff0c\u65b0\u65e7\u4e24\u4e2a\u7248\u672c\u7684\u5bc6\u94a5\u7684\u8fdc\u7aef\u670d\u52a1\u5668B\u5171\u7528\u4e00\u4e2aIP\uff0c\u8fd9\u6b63\u597d\u5c31\u662f\u7c7b\u4f3cmiddle-man\u653b\u51fb\u7684\u7279\u5f81\uff0c\u6240\u4ee5ssh\u8bbf\u95ee\u88ab\u53d6\u6d88\u3002\u8fd9\u91cc\u5c31\u9700\u8981\u6e05\u9664\u67d0\u4e2aip\u5730\u5740\u7684ssh\u7684\u5bc6\u94a5\uff0c\u518d\u91cd\u65b0ssh-key\u8bbf\u95ee\u4ee5\u5237\u65b0\u4e00\u6b21id_rsa.pub\u7684\u5bc6\u94a5\uff0c\u6e05\u9664\u548c\u5237\u65b0\u7684\u8fc7\u7a0b\u5c31\u662f\u91cd\u7f6essh\u7684key\u4e4b\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ssh-keygen -R 192.168.1.xxx (\u670d\u52a1\u5668ip\u5730\u5740)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u822c\u9700\u8981\u67e5\u9605\u8fd9\u7bc7\u9760RSA\u641c\u7d20\u51fa\u6765\u7684\u5de5\u5177\u6587\u7ae0\u7684\u65f6\u5019\uff0c [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[249],"tags":[508,368,362,507,370,364],"class_list":["post-2374","post","type-post","status-publish","format-standard","hentry","category-technology","tag-authorized_keys","tag-id_rsa-pub","tag-rsa","tag-ssh","tag-370","tag-364"],"_links":{"self":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/2374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2374"}],"version-history":[{"count":7,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/2374\/revisions"}],"predecessor-version":[{"id":2945,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/2374\/revisions\/2945"}],"wp:attachment":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}