【GIT】Git SSH Key 生成步骤(git-ssh 配置和使用)
2016-08-03 16:32
531 查看
Git SSH Key 生成步骤
Git是分布式的代码管理工具,远程的代码管理是基于SSH的,所以要使用远程的Git则需要SSH的配置。github的SSH配置如下:
一 、
设置Git的user name和email:
<span style="font-size:14px;">$ git config --global user.name "xuhaiyan"</span>
<span style="font-size:14px;">$ git config --global user.email "haiyan.xu.vip@gmail.com"</span>
二、生成SSH密钥过程:
1.查看是否已经有了ssh密钥:cd ~/.ssh
如果没有密钥则不会有此文件夹,有则备份删除
2.生存密钥:
$ ssh-keygen -t rsa -C “haiyan.xu.vip@gmail.com”
按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
3.添加密钥到ssh:ssh-add 文件名
需要之前输入密码。
4.在github上添加ssh密钥,这要添加的是“id_rsa.pub”里面的公钥。
打开https://github.com/ ,登陆xuhaiyan825,然后添加ssh。
5.测试:ssh git@github.com
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.
三、 开始使用github
1.获取源码:
<span style="font-size:14px;">$ git clone git@github.com:billyanyteen/github-services.git</span>
2.这样你的机器上就有一个repo了。
3.git于svn所不同的是git是分布式的,没有服务器概念。所有的人的机器上都有一个repo,每次提交都是给自己机器的repo
仓库初始化:
<span style="font-size:14px;">git init</span>
生成快照并存入项目索引:
<span style="font-size:14px;">git add</span>
文件,还有git rm,git mv等等…
项目索引提交:
<span style="font-size:14px;">git commit</span>
4.协作编程:
将本地repo于远程的origin的repo合并,
推送本地更新到远程:
<span style="font-size:14px;">git push origin master</span>
更新远程更新到本地:
<span style="font-size:14px;">git pull origin master</span>
补充:
添加远端repo:
<span style="font-size:14px;">$ git remote add upstream git://github.com/pjhyett/github-services.git</span>
重命名远端repo:
<span style="font-size:14px;">$ git://github.com/pjhyett/github-services.git为“upstream”</span>http://blog.csdn.net/hustpzb/article/details/8230454/
另附:git-ssh 配置和使用
1、设置Git的user name和email:(如果是第一次的话)
$ git config --global user.name "humingx" $ git config --global user.email "humingx@yeah.net"
2、生成密钥
$ ssh-keygen -t rsa -C "humingx@yeah.net"
连续3个回车。如果不需要密码的话。
最后得到了两个文件:
id_rsa和
id_rsa.pub。
如果不是第一次,就选择
overwrite.
3、添加密钥到ssh-agent
确保 ssh-agent 是可用的。ssh-agent是一种控制用来保存公钥身份验证所使用的私钥的程序,其实ssh-agent就是一个密钥管理器,运行ssh-agent以后,使用ssh-add将私钥交给ssh-agent保管,其他程序需要身份验证的时候可以将验证申请交给ssh-agent来完成整个认证过程。# start the ssh-agent in the background eval "$(ssh-agent -s)" Agent pid 59566
添加生成的 SSH key 到 ssh-agent。
$ ssh-add ~/.ssh/id_rsa
4、登陆Github, 添加 ssh 。
把id_rsa.pub文件里的内容复制到这里
5、测试:
$ ssh -T git@github.com
你将会看到:
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
Hi humingx! You've successfully authenticated, but GitHub does not provide shell access.
如果看到
Hi后面是你的用户名,就说明成功了。
6、修改.git
文件夹下config
中的url
。
修改前[remote "origin"] url = https://github.com/humingx/humingx.github.io.git fetch = +refs/heads/*:refs/remotes/origin/*
修改后
[remote "origin"] url = git@github.com:humingx/humingx.github.io.git fetch = +refs/heads/*:refs/remotes/origin/*
7、发布
https://segmentfault.com/a/1190000002645623
相关文章推荐
- Git SSH Key 生成步骤及使用
- git的ssh配置,包括多个git server配置ssh config,使用多个ssh identify
- SSH KEY 的生成与 Git 的基本使用
- Git SSH Key 生成步骤
- Git SSH Key 生成步骤
- Git SSH Key 生成步骤
- Git SSH Key 生成步骤
- git 的使用-linux上的配置 -ssh
- Git SSH Key 生成步骤
- Git SSH Key 生成步骤
- Git SSH Key 生成步骤(转)
- Git SSH Key 生成步骤
- Git的使用和SSH Key的生成
- Git SSH Key 生成步骤
- 替代svn,使用git做版本控制 TORTOISEGIT的SSH配置
- Git SSH Key 生成步骤
- Git SSH Key 生成步骤
- Git使用之基于SSH的Git服务器的客户端配置(下篇)
- Git SSH Key 生成步骤
- Git SSH Key 生成步骤