Github多賬戶多專案管理配置教程

來源:互聯網
上載者:User

下面我們一起來看看關於Github多賬戶多專案管理配置教程,希望此教程對各位同學會有所協助。

在 Github 建立了多個倉庫,並為每個倉庫使用了獨立的 deploy key,結果在進行 git push 操作時,提示沒有許可權。錯誤資訊類似:

ERROR: Permission to quyun/php-backend.git denied to quyun/aliyun-api-tools

官方的協助中有提到這個錯誤:

https://help.github.com/articles/error-permission-to-user-repo-denied-to-user-other-repo

不過對於許多應用情境,使用一個全域的 key 並不能滿足要求。

簡單分析下,我們可以發現 ssh 用戶端是通過類似:

git@github.com:quyun/aliyun-api-tools.git

這樣的 git 地址中的 user 和 host 來識別使用哪個本地私密金鑰的。

很明顯,如果 user 和 host 始終為 git 和 github.com,那麼就只能使用一個私密金鑰。

指定私密金鑰的方式也很簡單,編輯 ~/.ssh/config,添加類似如下配置即可:

Host php-backend.github.quyun.net
IdentityFile ~/.ssh/github-php-backend
User git

Host aliyun-api-tools.github.quyun.net
IdentityFile ~/.ssh/github-aliyun-api-tools
User git

配置格式很簡單,不多做解釋。

光是這樣指定當然不夠,你會發現我這裡的 host 已經不是 github.com 了。
我為每個倉庫使用了自己的 host,每個 host 的網域名稱做 CNAME 解析到 github.com,這樣 ssh 在串連時就可以區別不同的倉庫了。

來測試下:

# ssh -T git@php-backend.github.quyun.net
Hi quyun/php-backend! You’ve successfully authenticated, but GitHub does not provide shell access.

# ssh -T git@aliyun-api-utils.github.quyun.net
Hi quyun/aliyun-api-tools! You’ve successfully authenticated, but GitHub does not provide shell access.

可以看到 ssh 已經能夠根據不同 host 使用不同私密金鑰了。

最後,將你的 git 倉庫地址中的 host 改為新設定的 host 即可,如上面的:

git@github.com:quyun/aliyun-api-tools.git

改為:

git@aliyun-api-tools.github.quyun.net:quyun/aliyun-api-tools.git

在 windows 下也會出現這個問題,用同樣的方式解決即可!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.