1、前者可以随意克隆 github 上的项目,而不管是谁的;而后者则是你必须是你要克隆的项目的拥有者或管理员,且需要先添加 SSH key ,否则无法克隆。
2、https url 在 push 的时候是需要验证用户名和密码的;而 SSH 在 push 的时候,是不需要输入用户名的,如果配置 SSH key 的时候设置了密码,则需要输入密码的,否则直接是不需要输入密码的。
运行 git Bash 客户端,输入如下代码:
- $ cd ~/.ssh
- $ ls
这两个命令就是检查是否已经存在 id_rsa.pub 或 id_dsa.pub 文件,如果文件已经存在,那么你可以跳过步骤 2,直接进入步骤 3。
- ssh-keygen -t rsa -C ""
代码参数含义:
-t 指定密钥类型,默认是 rsa ,可以省略。
-C 设置注释文字,比如邮箱。
-f 指定密钥文件存储文件名。
以上代码省略了 -f 参数,因此,运行上面那条命令后会让你输入一个文件名,用于保存刚才生成的 SSH key 代码,如:
- Generating public/private rsa key pair.
- Enter file in which to save the key (/Users/Alan/.ssh/id_rsa):
- Enter passphrase (empty for no passphrase): #该密码是你push文件的时候要输入的密码,而不是github管理者的密码
- Enter same passphrase again:
- Your identification has been saved in /Users/Alan/.ssh/id_rsa.
- Your public key has been saved in /Users/Alan/.ssh/id_rsa.pub.
- The key fingerprint is:
- SHA256:WTKnBojIjX8do8O0RLxFYVT854mtfMFVhfTJ6BTsDx0
- The key's randomart image is:
- +---[RSA 2048]----+
- | ..o=+. .o..o|
- |..o..o.. . .=Eo|
- |.o...o+oo + .o.o+|
- | . +.+.oB .o+ o |
- | . * .S *.= |
- | . .. . * . |
- | . . . |
- | o . |
- | . |
- +----[SHA256]-----+
接着又会提示你输入两次密码(该密码是你 push 文件的时候要输入的密码,而不是 github 管理者的密码),
当然,你也可以不输入密码,直接按回车。那么 push 的时候就不需要输入密码,直接提交到 github 上了
- $ ssh -T
当你输入以上代码时,会有一段警告代码,如:
- he authenticity of host 'github.com (207.97.227.239)' can't be established.
- # RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
- # Are you sure you want to continue connecting (yes/no)?
这是正常的,你输入 yes 回车既可。如果你创建 SSH key 的时候设置了密码,接下来就会提示你输入密码,如:
- Enter passphrase for key '/c/Users/Administrator/.ssh/id_rsa':
注意:输入密码时如果输错一个字就会不正确,使用删除键是无法更正的。
密码正确后你会看到下面这段话,如:
- Hi username! You've successfully authenticated, but GitHub does not
- # provide shell access.
如果用户名是正确的, 你已经成功设置 SSH 密钥。如果你看到 "access denied" ,者表示拒绝访问
来源: http://www.bubuko.com/infodetail-1990913.html