我有一个学校和一个个人 Github,所以我为我的个人帐户制作了一个 SSH key 并将其链接起来。它总是只工作一次,然后给我
Push Failed
Git@github.com: Permission denied (publickey). Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
我删掉旧的SSH,重新做一个SSH后又可以正常工作了,但这显然是一个巨大的麻烦。我在 Windows 10 上,使用 Git Bash,IDE 是 IntelliJ。
有什么想法吗?谢谢。
最佳答案
我通过以下方式解决了这个问题:
1.在$USER_HOME/.ssh/
路径下创建一个名为config
的文件,然后添加如下内容。
# For school account
Host school_github
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_school
# For personal account
Host personal_github
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_personal
2.使用 git bash 运行以下命令:
更改学校 github 存储库配置
git remote rm origin
git remote add origin git@school_github:your_github_username/your_repo_name.git
你可以试试。
关于Github:每次使用后我都必须制作一个新的 SSH key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57846857/