簡體   English   中英

使用多個 ssh 密鑰/github 帳戶時獲取“未找到存儲庫”

[英]Getting 'repository not found' when using multiple ssh keys / github accounts

我一直在使用以下設置來在多個 ssh 密鑰和 github 帳戶之間切換。

首先,我在 .ssh/ 中有兩個鍵

id_rsa_work
id_rsa_work.pub
id_rsa_personal
id_rsa_personal.pub

以及這些鍵的配置

Host personal
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa_personal

Host work
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa_work

然后我可以通過執行在帳戶之間切換

ssh -T workssh -T personal

然后我使用兩個 gitconfig 文件來自動獲取 git 配置。

~/.gitconfig

[user]
    name = hex6b
    email = kaigo@personal.com

[includeIf "gitdir:~/work/"]
    path = ~/work/.gitconfig

~/work/.gitconfig

[user]
        name = My work name
        email = my.name@work.com

工作設置似乎工作正常,但是個人設置不允許我克隆新的存儲庫或推/拉現有的存儲庫。

錯誤:未找到存儲庫。 致命:無法從遠程存儲庫讀取。

請確保您擁有正確的訪問權限並且存儲庫存在。

不知道為什么它突然不起作用,也許是因為 github 引入了個人訪問令牌

當我執行ssh-add -l時,我也可以看到兩個鍵,所以我不需要將它們添加到 ssh 代理中。

我需要對來自 github 的 url 做任何特別的處理嗎? 通常我只是從代碼對話框中復制它們。

在此處輸入圖片說明

是的,您確實需要更改 URL。 Git FAQ 解釋了如何通過在每種情況下更改 URL來執行此操作

他們給出的示例配置如下所示:

# This is the account for author on git.example.org.
Host example_author
    HostName git.example.org
    User git
    # This is the key pair registered for author with git.example.org.
    IdentityFile ~/.ssh/id_author
    IdentitiesOnly yes
# This is the account for committer on git.example.org.
Host example_committer
    HostName git.example.org
    User git
    # This is the key pair registered for committer with git.example.org.
    IdentityFile ~/.ssh/id_committer
    IdentitiesOnly yes

在這種情況下,主機git.example.orgexample_authorexample_committer而不是git.example.org

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM