{"id":207308,"date":"2025-07-08T11:30:30","date_gmt":"2025-07-08T03:30:30","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207308\/"},"modified":"2025-07-08T11:30:30","modified_gmt":"2025-07-08T03:30:30","slug":"%e5%b8%a6%e6%9c%89%e7%a7%81%e6%9c%89-gitlab-ssh-%e7%9a%84-goland-%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207308\/","title":{"rendered":"\u5e26\u6709\u79c1\u6709 gitlab (ssh) \u7684 Goland \u6a21\u5757"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5e26\u6709\u79c1\u6709 gitlab (ssh) \u7684 Goland \u6a21\u5757<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-21 16:57:35<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5077\u5077\u52aa\u529b\uff0c\u6084\u65e0\u58f0\u606f\u5730\u53d8\u5f3a\uff0c\u7136\u540e\u60ca\u8273\u6240\u6709\u4eba\uff01\u54c8\u54c8\uff0c\u5c0f\u4f19\u4f34\u4eec\u53c8\u6765\u5b66\u4e60\u5566~\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5e26\u6709\u79c1\u6709 gitlab (ssh) \u7684 Goland \u6a21\u5757\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u4e0d\u77e5\u9053\u5927\u5bb6\u5bf9\u5176\u90fd\u6709\u591a\u5c11\u4e86\u89e3\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u770b\u4e00\u5427\uff01\u5f53\u7136\uff0c\u975e\u5e38\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u8bc4\u8bba\uff0c\u7ed9\u51fa\u5408\u7406\u7684\u5efa\u8bae\uff0c\u6211\u4eec\u4e00\u8d77\u5b66\u4e60\uff0c\u4e00\u8d77\u8fdb\u6b65\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u7f8e\u597d\u7684\u4e00\u5929\uff01\u6211\u5c1d\u8bd5\u4ece glide \u8fc1\u79fb\u5230 go \u6a21\u5757\uff08\u79c1\u4eba gitlab \u5b58\u50a8\u5e93\uff09 \u5e76\u901a\u8fc7 ssh \u7b7e\u51fa\u4ee3\u7801<\/p>\n<p>\u6211\u6709\u4e00\u4e2a\u7b80\u5355\u7684\u9879\u76ee\uff0c\u4ece\u79c1\u4eba gitlab \u5b58\u50a8\u5e93\u5bfc\u5165\u3002<\/p>\n<p>go.mod \u770b\u8d77\u6765\u50cf\uff1a<\/p>\n<pre>module my.private.package\/modtest\n\ngo 1.12\n\nrequire my.private.package\/statistics v1.0.0<\/pre>\n<p>\u5f53\u6211\u5c1d\u8bd5\u6784\u5efa\u6211\u7684\u5e94\u7528\u7a0b\u5e8f\u6216\u8fd0\u884c\u6d4b\u8bd5\u65f6\uff0c\u6211\u5f97\u5230\uff1a<\/p>\n<pre>go: my.private.package\/[email&nbsp;protected]: unrecognized import path \"my.private.package\/statistics\" (parse https:\/\/my.private.package\/statistics?go-get=1: no go-import meta tags ())\ngo: error loading module requirements<\/pre>\n<p>\u6211\u5c1d\u8bd5\u5c06\u8bbe\u7f6e\u6dfb\u52a0\u5230 git config\uff1a<\/p>\n<pre>[url \"ssh:\/\/[email&nbsp;protected]:9999\"]\n        insteadOf = https:\/\/my.private.package<\/pre>\n<p>\u4f46\u4ecd\u7136\u51fa\u73b0\u6b64\u9519\u8bef\u3002<\/p>\n<p>\u6709\u4ec0\u4e48\u529e\u6cd5\u53ef\u4ee5\u8ba9\u5b83\u53d1\u6325\u4f5c\u7528\u5417\uff1f \u8c22\u8c22\u3002 <\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u6211\u4e4b\u524d\u5904\u7406\u8fc7 go \u6a21\u5757\u548c\u79c1\u6709 gitlab\u3002\u6211\u4eec\u7684\u79c1\u4eba gitlab \u6709\u7ec4\u548c\u5b50\u7ec4\u3002\u60a8\u53ef\u80fd\u7f3a\u5c11\u7684\u90e8\u5206\u662f <code>~\/.netrc<\/code> \u5e76\u4e14\u60a8\u7684\u5168\u5c40 git \u914d\u7f6e\u53ef\u80fd\u4e0d\u6b63\u786e\u3002<\/p>\n<p>\u6211\u4e3a\u6b64\u5236\u5b9a\u4e86 github \u8981\u70b9\u3002\u60a8\u53ef\u4ee5\u5728\u8fd9\u91cc\u627e\u5230\u5b83\uff1a<\/p>\n<p>\u60a8\u53ef\u4ee5\u627e\u5230\u4e0b\u9762\u7c98\u8d34\u7684\u8981\u70b9\uff1a<\/p>\n<h1>\u95ee\u9898<\/h1>\n<p><code>go<\/code> \u547d\u4ee4\u884c\u5de5\u5177\u9700\u8981\u80fd\u591f\u4ece\u60a8\u7684\u79c1\u6709 gitlab \u83b7\u53d6\u4f9d\u8d56\u9879\uff0c\u4f46\u9700\u8981\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\u3002<\/p>\n<p>\u8fd9\u5047\u8bbe\u60a8\u7684\u79c1\u4eba gitlab \u6258\u7ba1\u5728 <code>privategitlab.company.com<\/code>\u3002<\/p>\n<h1>\u73af\u5883\u53d8\u91cf<\/h1>\n<p>\u5efa\u8bae\u4f7f\u7528\u4ee5\u4e0b\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<pre>export go111module=on\nexport goprivate=privategitlab.company.com\n<\/pre>\n<p>\u4e0a\u9762\u7684\u884c\u53ef\u80fd\u6700\u9002\u5408\u60a8\u7684 shell \u542f\u52a8\uff0c\u4f8b\u5982 <code>~\/.bashrc<\/code>\u3002<\/p>\n<h3>\u8bf4\u660e<\/h3>\n<p><code>go111module=on<\/code> \u544a\u8bc9 golang \u547d\u4ee4\u884c\u5de5\u5177\u60a8\u6b63\u5728\u4f7f\u7528\u6a21\u5757\u3002\u6211\u8fd8\u6ca1\u6709\u4f7f\u7528\u4e0d\u4f7f\u7528\u7684\u9879\u76ee\u5bf9\u6b64\u8fdb\u884c\u6d4b\u8bd5 \u79c1\u6709 gitlab \u4e0a\u7684 golang \u6a21\u5757\u3002<\/p>\n<p><code>goprivate=privategitlab.company.com<\/code> \u544a\u8bc9 golang \u547d\u4ee4\u884c\u5de5\u5177\u4e0d\u8981\u4f7f\u7528\u516c\u5171\u4e92\u8054\u7f51\u8d44\u6e90\u4f5c\u4e3a\u4e3b\u673a\u540d \u5217\u51fa\uff08\u5982\u516c\u5171\u6a21\u5757\u4ee3\u7406\uff09\u3002<\/p>\n<h1>\u4ece\u60a8\u7684\u79c1\u4eba gitlab \u83b7\u53d6\u4e2a\u4eba\u8bbf\u95ee\u4ee4\u724c<\/h1>\n<p>\u4e3a\u4e86\u5c06\u6765\u8bc1\u660e\u8fd9\u4e9b\u8bf4\u660e\uff0c\u8bf7\u9075\u5faa \u3002 \u6211\u77e5\u9053 golang \u547d\u4ee4\u884c\u5de5\u5177\u9700\u8981 <code>read_api<\/code> \u4f5c\u7528\u57df\u624d\u80fd\u5de5\u4f5c\uff0c\u6211\u53ef\u80fd\u6000\u7591 <code>read_repository<\/code> \u4f5c\u4e3a \u597d\u5427\uff0c\u4f46\u5c1a\u672a\u8bc1\u5b9e\u8fd9\u4e00\u70b9\u3002<\/p>\n<h1>\u8bbe\u7f6e <code>~\/.netrc<\/code><\/h1>\n<p>\u4e3a\u4e86\u8ba9 golang \u547d\u4ee4\u884c\u5de5\u5177\u5411 gitlab \u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\uff0c\u6700\u597d\u4f7f\u7528 <code>~\/.netrc<\/code> \u6587\u4ef6\u3002<\/p>\n<p>\u8981\u521b\u5efa\u8be5\u6587\u4ef6\uff08\u5982\u679c\u4e0d\u5b58\u5728\uff09\uff0c\u8bf7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>touch ~\/.netrc\nchmod 600 ~\/.netrc\n<\/pre>\n<p>\u73b0\u5728\u7f16\u8f91\u6587\u4ef6\u7684\u5185\u5bb9\u4ee5\u5339\u914d\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>machine privategitlab.company.com login username_here password token_here<\/pre>\n<p>\u5176\u4e2d <code>username_here<\/code> \u66ff\u6362\u4e3a\u60a8\u7684 gitlab \u7528\u6237\u540d\uff0c<code>token_here<\/code> \u66ff\u6362\u4e3a\u5728 \u4e0a\u4e00\u8282\u3002<\/p>\n<h1>\u5e38\u89c1\u9519\u8bef<\/h1>\n<p>\u4e0d\u8981<strong>\u4e0d\u8981<\/strong>\u4f7f\u7528\u7c7b\u4f3c\u4ee5\u4e0b\u5185\u5bb9\u8bbe\u7f6e\u5168\u5c40 git \u914d\u7f6e\uff1a<\/p>\n<pre>git config --global url.\":\".insteadof \"https:\/\/privategitlab.company.com\"\n<\/pre>\n<p>\u6211\u76f8\u4fe1\u5728\u64b0\u5199\u672c\u6587\u65f6\uff0cgolang \u547d\u4ee4\u884c\u5de5\u5177\u5e76\u4e0d\u5b8c\u5168\u652f\u6301 ssh git\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4 \u4e0e <code>~\/.netrc<\/code> \u51b2\u7a81\u3002<\/p>\n<h1>\u5956\u52b1\uff1assh \u914d\u7f6e\u6587\u4ef6<\/h1>\n<p>\u4e3a\u4e86\u5b9a\u671f\u4f7f\u7528 <code>git<\/code> \u5de5\u5177\uff0c\u800c\u4e0d\u662f golang \u547d\u4ee4\u884c\u5de5\u5177\uff0c\u8bbe\u7f6e <code>~\/.ssh\/config<\/code> \u6587\u4ef6\u4f1a\u5f88\u65b9\u4fbf\u3002 \u4e3a\u6b64\uff0c\u8bf7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>mkdir ~\/.ssh\nchmod 700 ~\/.ssh\ntouch ~\/.ssh\/config\nchmod 600 ~\/.ssh\/config\n<\/pre>\n<p>\u8bf7\u6ce8\u610f\uff0c\u4e0a\u8ff0\u6587\u4ef6\u548c\u76ee\u5f55\u7684\u6743\u9650\u5bf9\u4e8e ssh \u5728\u5176\u9ed8\u8ba4\u914d\u7f6e\u4e2d\u5de5\u4f5c\u81f3\u5173\u91cd\u8981 \u5927\u591a\u6570 linux \u7cfb\u7edf\u3002<\/p>\n<p>\u7136\u540e\uff0c\u7f16\u8f91 <code>~\/.ssh\/config<\/code> \u6587\u4ef6\u4ee5\u5339\u914d\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>Host privategitlab.company.com\n  Hostname privategitlab.company.com\n  User USERNAME_HERE\n  IdentityFile ~\/.ssh\/id_rsa<\/pre>\n<p>\u8bf7\u6ce8\u610f\u4e0a\u8ff0\u6587\u4ef6\u4e2d\u7684\u7a7a\u683c\u5f88\u91cd\u8981\uff0c\u5982\u679c\u4e0d\u6b63\u786e\u5c06\u4f7f\u6587\u4ef6\u65e0\u6548\u3002<\/p>\n<p>\u5176\u4e2d <code>username_here<\/code> \u662f\u60a8\u7684 gitlab \u7528\u6237\u540d\uff0c<code>~\/.ssh\/id_rsa<\/code> \u662f\u6587\u4ef6\u7cfb\u7edf\u4e2d ssh <em>\u79c1\u94a5<\/em>\u7684\u8def\u5f84\u3002 \u60a8\u5df2\u5c06\u5176<em>\u516c\u94a5<\/em>\u4e0a\u4f20\u5230 gitlab\u3002\u8fd9\u91cc\u662f \u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u5e26\u6709\u79c1\u6709 gitlab (ssh) \u7684 Goland \u6a21\u5757\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591aGolang\u77e5\u8bc6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207308","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207308"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207308\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}