git - 重复 `ssh-agent` 和 `ssh-add` 访问私有(private)存储库

标签 git github

生成 github 帐户的 ssh key 后,我创建一个新文件来保存 key :

  ssh-keygen  -f ~/.ssh/github 

然后执行以下步骤:

eval $(ssh-agent -s)
ssh-add ~/.ssh/github

添加将公钥添加到github帐户。

但是重启机器后,提示我没有访问私有(private)仓库的权限,

我必须重复

eval $(ssh-agent -s)
ssh-add ~/.ssh/github

获得对存储库的访问权限。

每次重新登录终端时,都应重复上述步骤。

如何解决这个问题?

最佳答案

您可以按照“Auto-launching ssh-agent on Git for Windows ”(对 Linux 也有效),将其复制到 Git shell 函数中的 ~/.profile 或 ~/.bashrc 文件中,该函数可以为您启动 SSH 代理。

.bashrc是始终会被读取的那个,如“What are the functional differences between .profile .bash_profile and .bashrc

.bash_profile or .profile is read by login shells, along with .bashrc; subshells read only .bashrc

确保您的 SSH key 有效 ( ssh -i /path/to/private/key <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="16717f6256717f627e63743875797b" rel="noreferrer noopener nofollow">[email protected]</a> ),因为最新版本的 Git 使用 new OpenSSH format .

关于git - 重复 `ssh-agent` 和 `ssh-add` 访问私有(private)存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56914844/

相关文章:

git - GitHub.com 的存储库大小限制

github - 通过Google Cloud Source Control自动部署Google Cloud Functions

github - 不能推送,git一个repo,一个用户,两台电脑

git - 版本控制建议

git - git stash apply 和 git stash apply --index 有什么区别?

macos - git分支切换需要半分钟?

Git - 在 .gitignore 中提交文件

git - 卡住 Git 分支

git - IntelliJ - Git 未安装 : Cannot identify version of git executable: no response

android - GitHub Android库中有哪些不同的许可证?