Git SSH Key生成步骤

说明:

Git是分布式的代码管理工具,远程的代码管理是可以基于SSH的,所以在使用git的时候需要去配置SSH,方便代码的提交。

Git的SSH配置如下

一、设置user name和email

首先,点击鼠标右键打开git cmd面板,操作如下图:
Git SSH Key生成步骤说明
Git SSH Key生成步骤说明

在git命令行中去配置user name和email,具体如下:

$ git config --global user.name "Your name"
$ git config --global user.email "[email protected]"

二、生成SSH**:

1、首先查看是否已经有了SSH**:

$ cd ~/.ssh

如果没有生成**,命令行中会提示没有.ssh文件夹

2、接下来去生成**:

$ ssh-****** -t rsa -C "[email protected]"

按3个回车,密码为空。

Your identification has been saved in /home/tekkub/.ssh/id_rsa.
Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.
The key fingerprint is:
………………

(其中第一输入参数是设置生成文件名称,默认为空即可,下面的两个是设置密码使用,同样也为空即可)
最后得到了两个文件:id_rsa和id_rsa.pub,对应的文件在C:\Users\Administrator.ssh下

3、添加**到ssh:ssh-add 文件名(需要之前输入密码。)

4、打开github页面,在github页面中去设置SSH生成的**。操作步骤如下:
Git SSH Key生成步骤说明
Git SSH Key生成步骤说明

注意:接下来需要去配置公钥,也就是刚刚生成的id_rsa.pub文件中的内容。

Git SSH Key生成步骤说明
将id_rsa.pub内容复制到github界面中对应key的位置即可,点击Add SSH key按钮,接下来输入github的密码就大功告成。
Git SSH Key生成步骤说明

5、测试:

$ ssh [email protected] 
The 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
Warning: Permanently added ‘github.com,207.97.227.239′ (RSA) to the list of known hosts.
ERROR: Hi tekkub! You’ve successfully authenticated, but GitHub does not provide shell access
Connection to github.com closed.

当你看到Hi tekkub! You’ve successfully authenticated的时候说明已经配置成功,接下来就开始你的github之旅吧!

Git的项目创建

一、创建一个github项目

(在这里个人建议现在Github上先创建项目的目录工程,方便后面的代码提交工作)
1、在github页面中先创建一个项目目录出来,操作如下图:
Git SSH Key生成步骤说明

2、添加远程仓库
Git SSH Key生成步骤说明

3、上传文件到github
如果在git push origin master时报错(类似于:Updates were rejected because the remotecontains work that you do not have locally),说明远程仓库比本地仓库更新,要先执行git pull origin mater.
Git SSH Key生成步骤说明
Git SSH Key生成步骤说明

这样你的项目就已经上传至你的github上去了。

相关文章: