为什么需要克隆公共Git存储库的计算机ssh密钥? [英] Why is a machine's ssh key required to clone a public Git repository?

查看:203
本文介绍了为什么需要克隆公共Git存储库的计算机ssh密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为克隆一个私人回购,我们需要验证计算机是否可信。但是,对于公共回购,不知道为什么git的目的是为机器请求ssh密钥,如果ssh密钥没有添加到github的设置中?

解决方案

如果通过SSH连接,Git(实际上是Git使用的SSH代理)将始终要求以私钥形式进行身份验证。这是因为SSH协议实际上并不关心你是在访问一个公共的还是私有的存储库。



你可以很容易地确定用于克隆的协议,远程URL。 SSH网址如下所示:


  1. ssh://git@github.com/< user> /< ; repo> .git

  2. git@github.com:< user> /< repo> .git

    但是,在GitHub上,您总是可以使用 git:// 克隆公共存储库, code>协议而不是 ssh:// ,它不需要认证:

      git clone git://github.com/< user> /< repo> .git 

    或者,使用HTTPS,它将(如果内存服务的话)只需要对私有存储库进行身份验证:

      git克隆https://github.com/<user>/<repo>.git 


    I think for clone a private repo, we need to verify the computer is trusted. But for a public repo, not sure why git is designed to ask for ssh key for a machine if the ssh key is not added in Settings of github?

    解决方案

    If you connect via SSH, Git (actually the SSH agent used by Git) will always require authentication in form of a private key. This is because the SSH protocol actually does not care whether you're accessing a public or private repository.

    You can easily determine the protocol that's used for cloning by looking at the remote URL. SSH urls look like this:

    1. ssh://git@github.com/<user>/<repo>.git
    2. git@github.com:<user>/<repo>.git

    However, on GitHub you can always clone public repositories using the git:// protocol instead of ssh://, which does not require authentication:

    git clone git://github.com/<user>/<repo>.git
    

    Alternatively, use HTTPS, which will (if memory serves) require authentication only for private repositories:

    git clone https://github.com/<user>/<repo>.git
    

    这篇关于为什么需要克隆公共Git存储库的计算机ssh密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆