gitlab 使用ssh key

 

要讓gitlab-runner能夠以deploy user身份執行git 操作而不用打帳密

------

ssh-keygen -C gitlab_worker ,要輸入檔名時一樣打gitlab_worker

把key放到 /home/gitlab-runner/.ssh下

 

把gitlab_worker.pub的內容貼到gitlab user,deploy 的sshkey

 

 

 

 

 

 

 

-C 的gitlab_worker 就會出現在 title位置

 

 

 

 

在/home/gitlab-runner/.ssh/ 下新增 一個 config file

 

 

 

填入

 

Host localhost
  IdentityFile /home/gitlab-runner/.ssh/gitlab_worker

 

localhost 是因為gitlab就在本機,所以用localhost
IdentityFile 則是指定 gitlab_worker 這個key的位置

 

 

 

 

最後透過 ssh 測試ssh到gitlab 可否成功
ssh -T -i /home/gitlab-runner/.ssh/gitlab_worker git@localhost

 

 

測試

git clone git@localhost:aaa/bbb/ccc.git

免打帳密就成功了

 

 

ref

https://stackoverflow.com/questions/6688655/select-private-key-to-use-with-git

https://sinyilin.github.io/git/20191024/1014042378/git 

 

posted on 2020-08-27 09:46  seako  阅读(634)  评论(0编辑  收藏  举报