【问题标题】:Unable to Git clone with a second personal github account无法使用第二个个人 github 帐户进行 Git 克隆
【发布时间】:2022-01-29 04:33:18
【问题描述】:

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

我生成了密钥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 clone 存储库时,我看到了

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

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

【问题讨论】:

    标签: git github ssh git-clone


    【解决方案1】:

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

    ssh -Tv github-unaccount
    

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

    然后使用,假设是类似Linux的环境:

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

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

    OP Astha Gupta 确认使用了错误的密钥,因为来自the comments

    我在 ssh 中有一个额外的条目configHost *,它指向了id_rsa

    【讨论】:

    • 哦,执行ssh -Tv github-unaccount 指向第一个帐户。 ``` 提供公钥:/Users/astha.gupta/.ssh/id_rsa RSA SHA256:blah 显式代理服务器接受密钥:/Users/astha.gupta/.ssh/id_rsa RSA SHA256:blah 显式代理认证成功(公钥) .已通过 github.com 身份验证 嗨 astha-first-account!您已成功验证 debug1:通道 0:空闲:客户端会话,nchannels 1 已传输:发送 3068,接收 3256 字节,在 0.2 秒内每秒字节数:发送 18356.3,接收 19481.1 debug1:退出状态 1 ```
    • @AsthaGupta 仔细检查/Users/astha.gupta/.ssh/config的内容:名为github-unaccount的Host条目应该引用IdentityFile ~/.ssh/id_rsa_unaccount,第二个键。
    • 是的,它是 100%。我想知道是否有办法将此信息加载到终端 # Account 2 (personal) - 我们正在添加的配置 Host github-unaccount HostName github.com User git IdentityFile ~/.ssh/id_rsa_unaccount
    • 我还比较了~/.ssh/id_rsa和~/.ssh/id_rsa_unaccount的内容,它们是不同的
    • ssh -Tv github-unaccount的末尾还有一个debug1: Exit status 1。是不是很阴险?
    猜你喜欢
    • 2023-04-10
    • 2021-01-28
    • 2015-07-13
    • 2016-02-14
    • 2012-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多