国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 操作系統 > 正文

Gitlab配置ssh連接

2024-06-28 16:02:40
字體:
來源:轉載
供稿:網友
原文地址

一般在管理遠程主機時,都用ssh登錄,ssh user@host,但是這樣每次會使用密碼。 使用ssh-keygen生成的密鑰對,然后將公鑰添加的目標主機的~/.ssh/authorized_keys文件中,當前主機就成為可信任的主機,下次使用ssh登錄時,就不用輸入密碼了。

Gitlab,Github都支持這種方式的連接,具體操作步驟如下:

第一步:生成密鑰對

使用ssh-keygen生成密鑰對:

ssh-keygen -t rsa -C "你的郵箱"

這樣就在主目錄下的.ssh目錄中生成了兩個文件id_rsaid_rsa.pubid_rsa中保存的是私鑰,id_rsa.pub中保存的是公鑰。

第二步:添加公鑰

拷貝公鑰到剪切板:

pbcopy < id_rsa.pub

在 個人資料->SSH Keys->Add new 頁面中粘貼公鑰,就添加完成了。

第三步:測試

ssh加-T選項測試目標服務是否可用:

ssh -T git@"你的gitlab服務器地址"

第一次連接時,會詢問是否信任主機,確認后輸入yes。如果看到Welcome to GitLab, Rusher!就算配置成功了,接下來就可以通過ssh來提交代碼了。

Windows

下載 Git-Bash生成密鑰對ssh-keygen -t rsa -C "你的郵箱"生成之后用 notepad c:/User/Administrator/.ssh/id_rsa.pub 打開文件,然后將公鑰添加的Gitlab中.測試 ssh -T git@"你的gitlab服務器地址"

(只使用客戶端可忽略這節內容)

在客戶端提交時發現以下錯誤:

/usr/local/lib/ruby/1.9.1/net/http.rb:762:in `initialize': getaddrinfo: Name or service not known (SocketError)from /usr/local/lib/ruby/1.9.1/net/http.rb:762:in `open'from /usr/local/lib/ruby/1.9.1/net/http.rb:762:in `block in connect'from /usr/local/lib/ruby/1.9.1/timeout.rb:54:in `timeout'from /usr/local/lib/ruby/1.9.1/timeout.rb:99:in `timeout'from /usr/local/lib/ruby/1.9.1/net/http.rb:762:in `connect'from /usr/local/lib/ruby/1.9.1/net/http.rb:755:in `do_start'from /usr/local/lib/ruby/1.9.1/net/http.rb:744:in `start'from /home/git/gitlab-shell/lib/gitlab_net.rb:64:in `get'from /home/git/gitlab-shell/lib/gitlab_net.rb:30:in `check'from ./check:11:in `<main>'

在Github的issue里找到說先運行一下/home/Git/gitlab-shell/bin/check 。先做檢測,發現和上面一樣的錯誤。看錯誤是找不到域名,所以在/etc/hosts中需要配置一個地址的映射。

127.0.0.1  YOUR_DOMIN # YOUR_DOMIN是在/home/git/gitlab-shell/config.yml中配置的gitlab_url

在配置Gitlab的時候一開始是用管理員賬戶做測試的,后來建了我自己的賬號做開發。這樣我的本地就有兩個Gitlab賬號,如果直接用ssh來提交代碼有問題,因為ssh默認使用一開始生成id_rsa那個密鑰對,但不同的賬號又不能對應到同一個公鑰上。如果多個賬戶一起用,還需要做些配置。

假如有兩個賬號:root和rusher。

第一步:為兩個賬戶分別生成密鑰對

提示在哪里存儲密鑰文件的時候,對不同的賬號填不同的路徑,root放在/Users/you/.ssh/id_rsa_gitlab_root下,rusher的放在/Users/you/.ssh/id_rsa_gitlab_rusher

ssh-keygen -t rsa -C rusher@you.comGenerating public/PRivate rsa key pair.Enter file in which to save the key (/Users/you/.ssh/id_rsa): /Users/you/.ssh/id_rsa_gitlab_rusherEnter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/you/.ssh/id_rsa_gitlab_rusher.Your public key has been saved in /Users/you/.ssh/id_rsa_gitlab_rusher.pub.ssh-keygen -t rsa -C root@you.comGenerating public/private rsa key pair.Enter file in which to save the key (/Users/you/.ssh/id_rsa): /Users/you/.ssh/id_rsa_gitlab_rootEnter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/you/.ssh/id_rsa_gitlab_root.Your public key has been saved in /Users/you/.ssh/id_rsa_gitlab_root.pub.

還是需要將兩個賬號的公鑰分別添加的各自賬號的SSH Keys中(rusher: id_rsa_gitlab_rusher.pub和root: id_rsa_gitlab_root.pub) 。

ssh-add /Users/you/.ssh/id_rsa_gitlab_rusherssh-add /Users/you/.ssh/id_rsa_gitlab_root

第二步:添加ssh配置文件

在.ssh目錄中添加config文件,此文件的為不同的賬戶添加別名(root: root_gitlab 和 rusher: rusher_gitlab),連接還是同一個服務器,但是使用不同的密鑰文件,所以才能將兩個賬號分開。

# for root Host root_gitlab  HostName git.you.com  User git  IdentityFile /Users/you/.ssh/id_rsa_gitlab# for rusherHost rusher_gitlab  HostName git.you.com  User git  IdentityFile /Users/you/.ssh/id_rsa_gitlab_rusher

配置完成后,使用ssh-add命令

接下來這樣使用別名測試,可以查看是否對應到了正確的賬號上:

ssh -T git@root_gitlab ssh -T git@rusher_gitlab

第三步:在git項目中使用別名

正常的項目,我們clone下來之后,origin對應的URL假設為: git@git.:Rusher/helloworld,現在需要做個改動,將git.要換成rusher_gitlab,

git remote set-url origin git@rusher_gitlab:Rusher/helloworld

如果是root用戶的項目:

git remote set-url origin git@root_gitlab:root/helloworld

以上配置ssh的方法同樣適用于Github,Bitbucket等網站。

Github Help

UPDATE 2013-08-16: 為不同賬號生成密鑰對后,需要使用ssh-add將密鑰添加進來,否則ssh不能使用正確的密鑰


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 屏东县| 惠来县| 桐庐县| 分宜县| 庆元县| 寻乌县| 富蕴县| 博白县| 饶阳县| 明溪县| 陵水| 北安市| 西峡县| 阳新县| 东方市| 阳谷县| 东海县| 金平| 曲水县| 黔江区| 同江市| 弥勒县| 宜阳县| 南昌市| 保康县| 禹州市| 潢川县| 昌邑市| 四川省| 惠来县| 靖安县| 微博| 扶风县| 始兴县| 林口县| 抚顺市| 麻江县| 富川| 白城市| 仪征市| 敖汉旗|