简体   繁体   English

使用 SSH 的 GitHub 克隆存储库不起作用

[英]GitHub clone repositories with SSH doesn't work

Type command:键入命令:

git clone git@github.com:Xingggg/Material-Design-Study-Notes.git

Terminal error message:终端错误信息:

 ssh_exchange_identification: Connection closed by remote host fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

I have added my public key in my GitHub account.我已经在我的 GitHub 帐户中添加了我的公钥。

I use HTTPS clone repositories it's OK.我使用HTTPS克隆存储库,没关系。
My machine is MacBook Pro我的机器是 MacBook Pro

Sound like you have not set up your ssh keys properly or they might be revoked and you cant use them.听起来您没有正确设置 ssh 密钥,否则它们可能会被撤销而您无法使用它们。

And I use https clone repo It's ok我使用 https clone repo 没关系

https use username password and not ssh. https使用用户名密码而不是 ssh。 Set the keys and switch the remote to ssh.设置密钥并将遥控器切换到 ssh。


Here is how to set it up:

  • Generate a new ssh key (or skip this step if you already have a key as you mentioned )生成一个新的 ssh 密钥(如果您已经有您提到的密钥,则跳过此步骤)
    ssh-keygen -t rsa -C "your@email"

  • Once you have your key set in home/.ssh directory (or Users/<your user>.ssh under windows), open it and copy the contenthome/.ssh目录(或 Windows 下的Users/<your user>.ssh )设置密钥后,打开它并复制内容


How to set up ssh key under your GitHub account?

  • Login to GitHub account登录GitHub账号
  • Click on the rancher on the top right ( Settings )点击右上角的牧场主( Settings
    在此处输入图片说明
  • Click on the SSH keys and GPG Keys单击SSH keys and GPG Keys
    在此处输入图片说明
  • Click on the New SSH key单击New SSH key
    在此处输入图片说明
  • Paste your key and save粘贴您的密钥并保存

Now it should work现在它应该工作


Note

After the first set up open terminal and run a git fetch so the key will be tested and added to your known hosts file.在第一次设置打开终端并运行git fetch ,密钥将被测试并添加到您known hosts文件中。

I use the same SSH Public key in the coding.net.我在coding.net 中使用相同的SSH 公钥。

The Coding is git server like GitHub in China. Coding 是 git 服务器,类似于中国的 GitHub。

I was in China, So I think the reason is the Great Firewall of China.我在中国,所以我认为原因是中国的防火墙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM