生成 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/