首页 > 解决方案 > 使用 Google Colab 克隆私有存储库的步骤

问题描述

我想在 Google Colab 中克隆一个私有仓库,

我在 colab 上打开了一个笔记本并执行了以下操作:

%cd "content/drive/My Drive/project"
!rm -rf /root/.ssh*
!mkdir /root/.ssh
!ssh-keygen -t rsa -b 4096 -C "githubname@github.com"

然后我打开了公钥

 !cat /root/.ssh/id_rsa.put

我复制了运行命令后显示的公钥,并使用此密钥在我的 GitHub 中创建了一个新密钥。

然后我尝试了以下方法:

!ssh-keyscan GitHub.com >> /root/.ssh/known_hosts
!chmod 644 /root/.ssh/known_hosts
!chmod 600 /root/ssh/id_rsa
!ssh -T github.com

然后我得到以下信息(权限被拒绝)

# github.com:22 SSH-2.0-babeld-d45c1532
# github.com:22 SSH-2.0-babeld-d45c1532
# github.com:22 SSH-2.0-babeld-d45c1532
Warning: Permanently added the RSA host key for IP address '140.82.113.3' to the list of known hosts.
root@github.com: Permission denied (publickey).

接下来我该怎么做?

标签: githubgoogle-colaboratory

解决方案


ssh -T github.com
root@github.com: Permission denied (publickey)

这是意料之中的:

  • 正确的测试是:

    ssh -T git@github.com
    
  • 与 GitHub 一起使用的正确 SSH URL 是:

    git@github.com:<me>/<myRepo>
    

您始终使用“ git”,而不是“ root”(或您当前的本地用户)作为远程用户来连接到 GitHub。

您的本地帐户仍然是“ root”(它包含公共和私人 SSH 密钥)

但是连接到 GitHub 意味着使用远程帐户git


推荐阅读