Github:每次使用后我都必须制作一个新的 SSH key

标签 github intellij-idea ssh ssh-keys

我有一个学校和一个个人 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/

相关文章:

javascript - 超链接到 GitHub 项目 HTML 作为带有参数的预览

java - 使用 Intellij Idea 和 gradle 在 App Engine 上调试本地主机

ruby - 每当有人通过 SSH 登录时调用进程

ruby-on-rails - 是否可以让 Capistrano 通过反向 SSH 隧道进行结帐?

git - 具有模块的多个 GitHub 根的 IntelliJ 项目

macos - 在新的 OS X 安装上安装 Homebrew 时出现问题(SSL 错误)

java - eclipse中的Swing无法访问类sun.java2d.loops

ios - 如何使用 iPhone 通过 SSH 连接到树莓派?

GitHub 操作 : "You' ve used 100% of included services for GitHub Storage (GitHub Actions and Packages)"after deleting all Artifacts

intellij-idea - IntelliJ 警告列表