git ssh连接

我们都知道git可以用http来连接,但是还有一个就是ssh,ssh是linux下面常用的通信协议
下面是一些SSH定义
SSH 为建立在应用层和传输层基础上的安全协议。SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用 SSH 协议可以有效防止远程管理过程中的信息泄露问题。SSH最初是UNIX系统上的一个程序,后来又迅速扩展到其他操作平台。SSH在正确使用时可弥补网络中的漏洞。SSH客户端适用于多种平台
RSA 非对称加密
我们不但要知道如何敲命令,我们还要知道其中的原理。那么RSA就是ssh用的加密方式,这里就不多说了,可以直接百度,原理就是你把public key给 github,你自己留着private key,然后github再给你public key, github 有自己的private key,你和github都有了对方的public key,你们就可以私聊了。

好了开始你的ssh和git连接之旅,主要有以下几步
1 用你的邮箱生成密钥对
ssh-keygen -t rsa -C "你的邮箱"
然后会打印出以下信息,告诉你key生成在/Users/username/.ssh/id_rsa 这里(username 是你登录的用户名,我用的是mac)

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/username/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/username/.ssh/id_rsa.
Your public key has been saved in /Users/username/.ssh/id_rsa.pub.
The key fingerprint is:
xxxxxxxx 你的邮箱
The key's randomart image is:
+--[ RSA 2048]----+
|        xxxxxxx
+-----------------+

2 查看你的public key
cat ~/.ssh/id_rsa.pub


2 放xx.pub到你的git server上(我这里是oschina, 也可以是github bitbucket 等git server)

3 测试 ssh -T [email protected]

这里会出现警告说 git.oschian.net 是不是你知道的 git server
The authenticity of host 'git.oschina.net (180.97.164.26)' can't be established.
RSA key fingerprint is xxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes

你输入yes 回车,出现下面信息
Warning: Permanently added 'git.oschina.net,180.97.164.26' (RSA) to the list of known hosts.
说gitserver的public key 已经加到你的本地了。在knowhost里面

然后会打印出
Welcome to Git@OSC, 你的username!
就说明连接成功了







猜你喜欢

转载自ycljf86.iteye.com/blog/2314223
今日推荐