无法 Git 使用第二个个人 github 帐户进行克隆

Unable to Git clone with a second personal github account

除了第一个帐户外,我还在笔记本电脑上添加了第二个 github 帐户。文档 https://betterprogramming.pub/how-to-use-multiple-github-accounts-with-one-computer-c9ba3f851b75 确实有很大帮助,但我在克隆可从第二个 github 帐户访问的存储库时遇到问题。

我生成了密钥 id_rsa_unaccountid_rsa_unaccount.pub 并将 id_rsa_unaccount.pub 的内容添加到第二个 github 帐户的 ssh 字段中。

>ls ~/.ssh  
config          id_rsa          id_rsa.pub      id_rsa_unaccount    id_rsa_unaccount.pub

更新了 ~/.ssh/config

# Account 1 (work or personal) - the default config
Host github.com
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa

# Account 2 (personal) - the config we are adding
Host github-unaccount
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa_unaccount

同时设置

git config user.name "Gupastha" 
git config user.email "asthagupta92+8@gmail.com"

然而,当我尝试 git 克隆存储库时,我看到了

git clone git@github-unaccount:Noble-Missions/itakeactions.git 
Cloning into 'itakeactions'...
ERROR: Repository not found.
fatal: Could not read from remote repository.

我也检查了多个堆栈溢出链接,但我还没有找到克隆的解决方案。任何人都可以轻推我吗?

首先检查您的第二个密钥是否被识别:

ssh -Tv github-unaccount

不需要 git@,因为它包含在您的 ~/.ssh/config

然后使用,假设Linux-like环境:

export GIT_SSH_COMMAND='ssh -v'
git clone github-unaccount:Noble-Missions/itakeactions.git 

您将看到在克隆操作期间考虑了哪些键。

OP Astha Gupta confirms the wrong key is used because, from :

I had an additional entry in the ssh config: Host *, which was pointing to id_rsa.