【问题标题】:How to use two different github accounts with SSH and Red Hat 7?如何在 SSH 和 Red Hat 7 中使用两个不同的 github 帐户?
【发布时间】:2020-06-02 18:47:30
【问题描述】:

我知道有很多这样的问题,但没有答案能够为 redhat 解决这个问题。我有一个 MACOS,有两个帐户,没什么大不了的,但在 Red Hat 上它就不起作用。

我有两个帐号

https://github.com/USER1/REPOSITORY_A.git
https://github.com/USER2/REPOSITORY_B.git

我之前的设置是创建一个用于 USER1 的 SSH 密钥:

~/.ssh/id_rsa.pub 

和第二个 USER2 上:

~/.ssh/USER2/id_rsa.pub

添加了 ssh 密钥,例如:

ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/USER2/id_rsa

我必须在 github 上为每个密钥添加自己的帐户 SSH 密钥。而且我必须像这样设置我的配置:

vi ~/.ssh/config

Host github.com
    Hostname ssh.github.com
    Port 443
    AddKeysToAgent yes
    IdentityFile ~/.ssh/id_rsa
    User git

Host user2-github.com
    HostName github.com
    AddKeysToAgent yes
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/user2/id_rsa
    User git

Host *
    AddKeysToAgent yes
    IdentityFile ~/.ssh/id_rsa

而且我必须设置 USER2 本地存储库,例如:

git remote set-url origin git@user2-github.com:user2/REPOSITORY_B.git

在 MACOS 上,一切都像魅力一样,但在 redhat 上,当我尝试推送本地 (USER2) 存储库时,它会尝试使用“USER1”凭据...我找不到解决方案,所以我认为我需要你的帮助...

如何在 SSH 和 Red Hat 7 中使用两个不同的 github 帐户?

【问题讨论】:

    标签: git ssh redhat multiple-accounts


    【解决方案1】:

    首先,在 RedHat 上,检查使用的远程 URL:

    git remote -v
    

    如果您在那里看到https://,那么再多的 SSH 调整也无济于事:SSH 密钥将被忽略。 git config credential.helper 可能会显示一个凭据缓存,它会缓存 USER1 凭据(用户名/密码)

    第二个,确保你的 URL 是 user2-github.com:user2/REPOSITORY_B.git(不需要git@,因为用户 git 是在 SSH 配置文件中指定的)

    【讨论】:

    • 您好,关于git config credential.helper 的问题,没有缓存。这是一个很好的提示,即使应该是它......但是不,没有缓存......关于 URL,我做了两种方式:``` git@user2-github.com:user2/REPOSITORY_B.git user2- github.com:user2/REPOSITORY_B.git ``` 但两者都给了我同样的错误:ssh: connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 也许 git 忽略了~/.ssh/config 上的 ssh 配置文件?
    • @MiguelDias `git@user2-github.com` 肯定会忽略你的 ~/.ssh/config。先试试ssh -Tv user2-github.com
    猜你喜欢
    • 1970-01-01
    • 2019-07-10
    • 1970-01-01
    • 2021-03-28
    • 2022-10-23
    • 2018-03-22
    • 2018-06-02
    • 1970-01-01
    • 2011-03-14
    相关资源
    最近更新 更多