{"id":19232,"date":"2024-11-19T10:10:51","date_gmt":"2024-11-19T02:10:51","guid":{"rendered":"https:\/\/fwq.ai\/blog\/19232\/"},"modified":"2024-11-19T10:10:51","modified_gmt":"2024-11-19T02:10:51","slug":"git-%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9-ssh","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/19232\/","title":{"rendered":"git \u5982\u4f55\u4fee\u6539 ssh"},"content":{"rendered":"<p>git \u662f\u76ee\u524d\u7a0b\u5e8f\u5458\u4f7f\u7528\u6700\u9891\u7e41\u7684\u4ee3\u7801\u7248\u672c\u7ba1\u7406\u5de5\u5177\uff0c\u800c ssh \u662f\u5b9e\u73b0 git \u4ee3\u7801\u63a8\u9001\u548c\u62c9\u53d6\u7684\u5173\u952e\u8ba4\u8bc1\u65b9\u5f0f\u4e4b\u4e00\u3002\u4f46\u662f\uff0c\u6211\u4eec\u6709\u65f6\u5019\u9700\u8981\u4fee\u6539 ssh\uff0c\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5c06\u4f1a\u4e3a\u60a8\u63d0\u4f9b\u4e00\u4e9b\u5173\u4e8e\u5982\u4f55\u4fee\u6539 ssh \u7684\u7b80\u5355\u65b9\u6cd5\uff0c\u5e76\u89e3\u91ca git \u8ba4\u8bc1\u6d41\u7a0b\u7684\u57fa\u672c\u77e5\u8bc6\u3002<\/p>\n<p>Git \u8ba4\u8bc1\u6d41\u7a0b<\/p>\n<p>\u5728\u4e86\u89e3\u5982\u4f55\u4fee\u6539 SSH \u4e4b\u524d\uff0c\u8ba9\u6211\u4eec\u9996\u5148\u4e86\u89e3\u4e00\u4e0b Git \u5982\u4f55\u8ba4\u8bc1\u60a8\u7684\u8eab\u4efd\u3002Git \u5e95\u5c42\u4f7f\u7528 Secure Shell\uff08SSH\uff09\u8fdb\u884c\u5b89\u5168\u8ba4\u8bc1\u3002SSH \u63d0\u4f9b\u4e86\u4e00\u79cd\u52a0\u5bc6\u7684\u901a\u4fe1\u534f\u8bae\uff0c\u53ef\u4ee5\u4fdd\u62a4\u6570\u636e\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u7684\u9690\u79c1\u6027\u3001\u5b8c\u6574\u6027\u548c\u53ef\u9a8c\u8bc1\u6027\u3002\u5728 Git \u7684\u8eab\u4efd\u9a8c\u8bc1\u6d41\u7a0b\u4e2d\uff0cSSH \u4f1a\u4f7f\u7528\u516c\u94a5\u52a0\u5bc6\u6280\u672f\u5b9e\u73b0\u8eab\u4efd\u9a8c\u8bc1\uff0c\u7b80\u5355\u7684\u6d41\u7a0b\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u672c\u5730 Git \u8fd0\u884c ssh-keygen \u751f\u6210\u4e00\u4e2a\u516c\u94a5\u548c\u4e00\u4e2a\u79c1\u94a5.<\/li>\n<li>\u5c06\u516c\u94a5\u6dfb\u52a0\u5230\u60a8\u7684 Git \u8d26\u6237\u7684\u5b58\u50a8\u5e93\u7684 SSH Key \u9009\u9879\u5361\u4e2d.<\/li>\n<li>\u5728\u4ece\u4ed3\u5e93\u62c9\u51fa\u4ee3\u7801\u6216\u8005\u63d0\u4ea4\u4ee3\u7801\u65f6\uff0c\u4f7f\u7528 SSH \u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1, \u5982\u679c\u516c\u94a5\u80fd\u4e0e\u79c1\u94a5\u5339\u914d\uff0c\u5219\u8eab\u4efd\u9a8c\u8bc1\u6210\u529f.<\/li>\n<\/ol>\n<p>\uff08\u6ce8\uff1a\u5982\u679c\u60a8\u4f7f\u7528 HTTPS \u534f\u8bae\u8fdb\u884c Git \u901a\u4fe1\uff0c\u5219\u8fd9\u4e2a\u8fc7\u7a0b\u4e0d\u6d89\u53ca SSH \u8ba4\u8bc1\u3002\u800c\u662f\u76f4\u63a5\u4f7f\u7528\u60a8 Git \u8d26\u6237\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\uff09<\/p>\n<p>\u73b0\u5728\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u5982\u4f55\u4fee\u6539 SSH\u3002<\/p>\n<p>\u4fee\u6539 SSH \u7684\u65b9\u6cd5<\/p>\n<p>\u4fee\u6539 SSH \u901a\u5e38\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4e00\u79cd\u662f\u76f4\u63a5\u7f16\u8f91 SSH \u914d\u7f6e\u6587\u4ef6\uff0c\u53e6\u4e00\u79cd\u662f\u901a\u8fc7 Git Bash \u8fd0\u884c SSH \u547d\u4ee4\u6765\u914d\u7f6e\u3002\u6211\u4eec\u4e00\u4e2a\u4e00\u4e2a\u6765\u770b\u3002<\/p>\n<p>\u7b2c\u4e00\u79cd\u65b9\u6cd5\uff1a\u901a\u8fc7\u7f16\u8f91 SSH \u914d\u7f6e\u6587\u4ef6\u4fee\u6539 SSH<\/p>\n<ol>\n<li>\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00 SSH \u914d\u7f6e\u6587\u4ef6\uff0cWindows \u7528\u6237\u901a\u5e38\u5728 C:Users\u7528\u6237\u540d.ssh \u76ee\u5f55\u4e2d\uff0cLinux \u6216 Mac \u7528\u6237\u5219\u5728 ~\/.ssh \u76ee\u5f55\u4e2d\u3002<\/li>\n<li>\n<p>\u5982\u679c\u60a8\u6ca1\u6709\u914d\u7f6e SSH\uff0c\u5219 ssh \u6587\u4ef6\u5939\u5c06\u4e0d\u5b58\u5728\uff0c\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u5728 Git Bash \u4e2d\u521b\u5efa\u4e00\u4e2a SSH \u5bc6\u94a5\u3002\u5728 Git Bash \u4e2d\u8f93\u5165\uff1a<\/p>\n<p>ssh-keygen -t rsa -C &#8220;\u60a8\u7684\u90ae\u4ef6\u5730\u5740&#8221;<\/p>\n<\/li>\n<li>\u5728\u60a8\u7684 Git \u8d26\u6237\u9875\u9762\u4e0a\u5c06\u516c\u94a5\u6dfb\u52a0\u5230\u201cSSH\u5bc6\u94a5\u201d\u9009\u9879\u5361\uff0c\u60a8\u53ef\u4ee5\u6253\u5f00\u81ea\u5df1\u7684\u8d26\u6237\uff0c\u9009\u62e9settings\u7136\u540e\u9009\u62e9SSH Keys,\u5c06\u751f\u6210\u7684id_rsa.pub \u590d\u5236\u5230SSH Key\u4e2d\u5373\u53ef\u3002<\/li>\n<li>\n<p>\u7f16\u8f91 config \u6587\u4ef6\u3002\u5982\u679c\u8be5\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u5219\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\u3002\u7531\u4e8e\u8fd9\u91cc\u4e0d\u662f\u4ecb\u7ecd SSH \u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u6211\u4eec\u53ea\u7b80\u5355\u4ecb\u7ecd\u901a\u8fc7\u5411 config \u6587\u4ef6\u6dfb\u52a0\u65b0\u4e3b\u673a\u7684\u65b9\u6cd5\uff0c\u4ee5\u4fbf\u4f7f\u7528\u65b0\u914d\u7f6e\u8986\u76d6\u9ed8\u8ba4\u8bbe\u7f6e\u3002<\/p>\n<p>Host github.com <br \/>HostName github.com <br \/>User git <br \/>IdentityFile ~\/.ssh\/id_rsa_github<\/p>\n<\/li>\n<\/ol>\n<p>\u5728\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u65b0\u4e3b\u673a\u7684\u540d\u79f0\uff0c\u540d\u79f0\u4e3a github.com\uff0c\u4e3b\u673a\u540d\u4e3a github.com\uff0c\u7528\u6237\u540d\u4e3a git\u3002IdentityFile \u9009\u9879\u6307\u5b9a\u4e86\u65b0\u7684\u79c1\u94a5\u6587\u4ef6\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u7b2c\u4e8c\u79cd\u65b9\u6cd5\uff1a\u901a\u8fc7 Git Bash \u8fd0\u884c SSH \u547d\u4ee4\u914d\u7f6e SSH<\/p>\n<ol>\n<li>\u542f\u52a8 Git Bash\u3002<\/li>\n<li>\u8fd0\u884c ssh-keygen \u547d\u4ee4\u3002\u5b83\u5c06\u63d0\u793a\u60a8\u8f93\u5165\u65b0\u7684\u6587\u4ef6\u540d\u548c\u8def\u5f84\uff0c\u6216\u8005\u60a8\u53ef\u4ee5\u4f7f\u7528\u9ed8\u8ba4\u8bbe\u7f6e\u3002<\/li>\n<li>\u5c06\u751f\u6210\u7684\u516c\u94a5\u6dfb\u52a0\u5230\u60a8\u7684 Git \u8d26\u6237\u4e2d\uff0c\u8bbf\u95ee GitHub \u6216\u5176\u4ed6 Git \u6258\u7ba1\u670d\u52a1\u5e76\u767b\u5f55\u3002<\/li>\n<li>\u6d4b\u8bd5\u65b0\u5bc6\u94a5\u662f\u5426\u8d77\u4f5c\u7528\u3002\u8f93\u5165 ssh -T git@host\uff0c\u5176\u4e2d host \u662f\u60a8\u60f3\u8981\u6d4b\u8bd5\u7684\u4e3b\u673a\u540d\u3002\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u4f1a\u770b\u5230\u4e00\u4e2a\u6b22\u8fce\u6d88\u606f\uff0c\u6d88\u606f\u544a\u8bc9\u60a8\uff0c\u60a8\u5df2\u8fde\u63a5\u5230 Git \u6258\u7ba1\u670d\u52a1\u3002<\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u662f\u4e24\u79cd\u901a\u8fc7\u4fee\u6539 SSH \u6765\u6267\u884c Git \u8eab\u4efd\u9a8c\u8bc1\u7684\u7b80\u5355\u65b9\u6cd5\u3002<\/p>\n<p>\u7ed3\u8bba<\/p>\n<p>SSH \u662f Git \u5b89\u5168\u8ba4\u8bc1\u7684\u5173\u952e\uff0c\u4e5f\u662f Git \u5de5\u4f5c\u7684\u5fc5\u8981\u6761\u4ef6\u3002\u65e0\u8bba\u60a8\u662f\u65b0\u624b\u8fd8\u662f Git \u8001\u624b\uff0c\u4e86\u89e3\u5982\u4f55\u4fee\u6539 ssh \u90fd\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002\u5e0c\u671b\u4e0a\u8ff0\u65b9\u6cd5\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u53bb\u8bd5\u8bd5\u5427\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fgit \u5982\u4f55\u4fee\u6539 ssh\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>git \u662f\u76ee\u524d\u7a0b\u5e8f\u5458\u4f7f\u7528\u6700\u9891\u7e41\u7684\u4ee3\u7801\u7248\u672c\u7ba1\u7406\u5de5\u5177\uff0c\u800c ssh \u662f\u5b9e\u73b0 git \u4ee3\u7801\u63a8\u9001\u548c\u62c9\u53d6\u7684\u5173\u952e\u8ba4\u8bc1\u65b9\u5f0f\u4e4b\u4e00\u3002\u4f46\u662f\uff0c\u6211\u4eec\u6709\u65f6\u5019\u9700\u8981\u4fee\u6539 ssh\uff0c\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5c06\u4f1a\u4e3a\u60a8\u63d0\u4f9b\u4e00\u4e9b\u5173\u4e8e\u5982\u4f55\u4fee\u6539 ssh \u7684\u7b80\u5355\u65b9\u6cd5\uff0c\u5e76\u89e3\u91ca git \u8ba4\u8bc1\u6d41\u7a0b\u7684\u57fa\u672c\u77e5\u8bc6\u3002 Git \u8ba4\u8bc1\u6d41\u7a0b \u5728\u4e86\u89e3\u5982\u4f55\u4fee\u6539 SSH \u4e4b\u524d\uff0c\u8ba9\u6211\u4eec\u9996\u5148\u4e86\u89e3\u4e00\u4e0b Git \u5982\u4f55\u8ba4\u8bc1\u60a8\u7684\u8eab\u4efd\u3002Git \u5e95\u5c42\u4f7f\u7528 Secure Shell\uff08SSH\uff09\u8fdb\u884c\u5b89\u5168\u8ba4\u8bc1\u3002SSH \u63d0\u4f9b\u4e86\u4e00\u79cd\u52a0\u5bc6\u7684\u901a\u4fe1\u534f\u8bae\uff0c\u53ef\u4ee5\u4fdd\u62a4\u6570\u636e\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u7684\u9690\u79c1\u6027\u3001\u5b8c\u6574\u6027\u548c\u53ef\u9a8c\u8bc1\u6027\u3002\u5728 Git \u7684\u8eab\u4efd\u9a8c\u8bc1\u6d41\u7a0b\u4e2d\uff0cSSH \u4f1a\u4f7f\u7528\u516c\u94a5\u52a0\u5bc6\u6280\u672f\u5b9e\u73b0\u8eab\u4efd\u9a8c\u8bc1\uff0c\u7b80\u5355\u7684\u6d41\u7a0b\u5982\u4e0b\uff1a \u672c\u5730 Git \u8fd0\u884c ssh-keygen \u751f\u6210\u4e00\u4e2a\u516c\u94a5\u548c\u4e00\u4e2a\u79c1\u94a5. \u5c06\u516c\u94a5\u6dfb\u52a0\u5230\u60a8\u7684 Git \u8d26\u6237\u7684\u5b58\u50a8\u5e93\u7684 SSH Key \u9009\u9879\u5361\u4e2d. \u5728\u4ece\u4ed3\u5e93\u62c9\u51fa\u4ee3\u7801\u6216\u8005\u63d0\u4ea4\u4ee3\u7801\u65f6\uff0c\u4f7f\u7528 SSH \u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1, \u5982\u679c\u516c\u94a5\u80fd\u4e0e\u79c1\u94a5\u5339\u914d\uff0c\u5219\u8eab\u4efd\u9a8c\u8bc1\u6210\u529f. \uff08\u6ce8\uff1a\u5982\u679c\u60a8\u4f7f\u7528 HTTPS \u534f\u8bae\u8fdb\u884c Git \u901a\u4fe1\uff0c\u5219\u8fd9\u4e2a\u8fc7\u7a0b\u4e0d\u6d89\u53ca SSH \u8ba4\u8bc1\u3002\u800c\u662f\u76f4\u63a5\u4f7f\u7528\u60a8 Git \u8d26\u6237\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\uff09 \u73b0\u5728\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u5982\u4f55\u4fee\u6539 SSH\u3002 \u4fee\u6539 SSH \u7684\u65b9\u6cd5 \u4fee\u6539 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-19232","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/19232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=19232"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/19232\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=19232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=19232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=19232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}