1. 设置Git的user name和email:(如果是第一次的话)
-
$ git config --global user.name "ue90"
-
$ git config --global user.email "ylty@163.com"
配置完成后可以通过
查看、修改配置,内容如下:
-
[user]
-
name = ue90
-
email = ylty@163.com
2. 生成密钥
-
ssh-keygen -t rsa -C "ylty@163.com"
如果不需要密码的话,连续三个回车,就可以了。在~/.ssh/目录下会生成id_rsa和id_rsa.pub两个文件。
-
$ ssh-keygen -t rsa -C "ylty@163.com"
-
Generating public/private rsa key pair.
-
Enter file in which to save the key (/c/Users/lj/.ssh/id_rsa):
-
Created directory '/c/Users/lj/.ssh'.
-
Enter passphrase (empty for no passphrase):
-
Enter same passphrase again:
-
Your identification has been saved in /c/Users/lj/.ssh/id_rsa.
-
Your public key has been saved in /c/Users/lj/.ssh/id_rsa.pub.
-
The key fingerprint is:
-
SHA256:WHtPVMrdlDy6A0FeW7lIiRlmkL/m3ag007PLcrS4zEw ylty@163.com
-
The key's randomart image is:
-
+---[RSA 2048]----+
-
| .+=+.+.+|
-
| .+=.*oB |
-
| . ..*.+ +|
-
| o . + o . |
-
| . S . + . |
-
| . =.+ |
-
| oE=o= . |
-
| *++=o. |
-
| *=+. |
-
+----[SHA256]-----+
3. 添加密钥到ssh-agent
确保 ssh-agent 是可用的。ssh-agent是一种控制用来保存公钥身份验证所使用的私钥的程序,其实ssh-agent就是一个密钥管理器,运行ssh-agent以后,使用ssh-add将私钥交给ssh-agent保管,其他程序需要身份验证的时候可以将验证申请交给ssh-agent来完成整个认证过程。
-
#验证ssh-agent是否在运行
-
eval "$(ssh-agent -s)"
-
Agent pid 12356
添加生成的 SSH key 到 ssh-agent
4. 登陆git添加ssh key
登陆github官网:
按照以上步骤将~/.ssh/id_rsa.pub中的公钥信息添加到github中。
5. 测试
在git bash中输入以上命令,会看到
-
$ ssh -T git@github.com
-
The authenticity of host 'github.com (192.30.255.113)' can't be established.
-
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
-
Are you sure you want to continue connecting (yes/no)? yes
-
Warning: Permanently added 'github.com,192.30.255.113' (RSA) to the list of know n hosts.
-
Hi ue90! You've successfully authenticated, but GitHub does not provide shell access.
完成以上5步就可以从github下载代码了。
阅读(1376) | 评论(0) | 转发(0) |