Git使用ssh key
生成ssh key步骤
这里以配置github的ssh key为例:
1. 配置git用户名和邮箱
git config user.name
"用户名"
git config user.email
"邮箱"
在config后加上 --global 即可全局设置用户名和邮箱。
2. 生成ssh key
ssh-keygen
-t rsa -C
"邮箱"
然后根据提示连续回车即可在~/.ssh目录下得到id_rsa和id_rsa.pub两个文件,id_rsa.pub文件里存放的就是我们要使用的key。
3. 上传key到github
clip < ~/.ssh/id_rsa.pub
- 复制key到剪贴板
- 登录github
- 点击右上方的Accounting settings图标
- 选择 SSH key
- 点击 Add SSH key
4. 测试是否配置成功
ssh -T git@github.com
如果配置成功,则会显示:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
解决本地多个ssh key问题
有的时候,不仅github使用ssh key,工作项目或者其他云平台可能也需要使用ssh key来认证,如果每次都覆盖了原来的id_rsa文件,那么之前的认证就会失效。这个问题我们可以通过在~/.ssh目录下增加config文件来解决。
下面以配置搜狐云平台的ssh key为例。
1. 第一步依然是配置git用户名和邮箱
git config user.name
"用户名"
git config user.email
"邮箱"
2. 生成ssh key时同时指定保存的文件名
ssh-keygen
-t rsa -f ~/.ssh/id_rsa.sohu -C
"email"
上面的id_rsa.sohu就是我们指定的文件名,这时~/.ssh目录下会多出id_rsa.sohu和id_rsa.sohu.pub两个文件,id_rsa.sohu.pub里保存的就是我们要使用的key。
3. 新增并配置config文件
添加config文件
如果config文件不存在,先添加;存在则直接修改
touch ~/.ssh/config
在config文件里添加如下内容(User表示你的用户名)
Host *.cloudscape.sohu.com
IdentityFile ~/.ssh/id_rsa.sohu
User test
4. 上传key到云平台后台(省略)
5. 测试ssh key是否配置成功
ssh -T git@git.cloudscape.sohu.com
成功的话会显示:
Welcome to GitLab, username!
至此,本地便成功配置多个ssh key。日后如需添加,则安装上述配置生成key,并修改config文件即可。
端口
端口可能会被防火墙屏蔽,可以设置SSH使用HTTPS的403端口。
测试HTTPS端口是否可用
2 |
$ ssh -T -p 443 git@ssh.github.com |
编辑SSH配置文件 ~/.ssh/config 如下:
2 |
测试是否配置成功
2 |
$ ssh -T git@github.com |
Caching your GitHub password in Git
If you're cloning GitHub repositories using HTTPS, you can use a credential helper to tell Git to remember your GitHub username and password every time it talks to GitHub.
If you clone GitHub repositories using SSH, then you authenticate using SSH keys instead of a username and password. For help setting up an SSH connection, see Generating an SSH Key.
Tip: You need Git 1.7.10 or newer to use the credential helper.
The credential helper is included with GitHub Desktop. The app also provides a Git shell so you won't ever need to install and configure Git manually. For more information, see "Getting Started with GitHub Desktop."
If you prefer working with the command line, you can also install a native Git shell, such as msysgit. With msysgit, running the following in the command line will store your credentials:
git config --global credential.helper wincred
一些错误
disconnected no supported authentication methods available(server sent: publickey,keyboard interae)
安装Git客户端后,进行PULL时报如下错误
disconnected no supported authentication methods available(server sent: publickey,keyboard interactive)解决方案
因为TortoiseGit和Git的冲突
我们需要把TortoiseGit设置改正如下。
1.找到TortoiseGit -> Settings -> Network
2.将SSH client指向~\Git\bin\ssh.exe(Git安装路径下)(Git2.7版本下在C:\Program Files\Git\usr\bin)
然后便可正确push和pull
Git使用ssh key的更多相关文章
- git配置SSH Key,上传本地代码至github
git配置全局的name和email git config --global user.name "name" git config --global user.email &qu ...
- Git配置SSH Key
最近看到很多人在配置Git时,遇到很问题,网上教程千篇一律.这儿自己单独记录一份. Git配置SSH Key 1.检查本机是否有ssh key设置,切换到.ssh目录 $ cd ~/.ssh 或cd ...
- git生成ssh key及本地解决多个ssh key的问题
git生成ssh key及本地解决多个ssh key的问题 ssh是一种网络协议,用于计算机之间的加密登录.ssh原理及应用可参考: SSH原理与运用(一):远程登录 生成ssh key步骤 这里以配 ...
- 一台电脑上配置多个git的ssh key
前几天公司的代码库全部迁移到了阿里云上,在配置git的ssh key的时候遇到了一个问题,那就是自己的密钥在添加时提示已经存在,原来是自己的个人账号上已经添加过这个密钥了,公司分配的账号就不能再添加这 ...
- Git 中 SSH key 生成步骤
由于本地Git仓库和GitHub仓库之间的传输是通过SSH加密的,所以必须要让github仓库认证你SSH key,在此之前,必须要生成SSH key. 第1步:创建SSH Key.在windows下 ...
- git 配置 .ssh key
1.安装git软件: 2.打开本地git bash,使用如下命令生成ssh公钥和私钥对: ssh-keygen -t rsa -C 'xxx@xxx.com' 然后一路回车(-C 参数是你的邮箱 ...
- Git 生成SSH Key
背景:服务器是LINUX系统(centos7),使用GitLab管理git代码库.各个客户端通过sourcetree 工具,采用SSH获取.提交代码.使用SSH的方式需要公钥和私钥.下面介绍秘钥的生成 ...
- git生成ssh key步骤并添加到github网站
0: 查看是否已经有了ssh密钥 执行命令:cd ~/.ssh 如果没有密钥则不会有此文件夹,有则备份删除 1:使用 Git Bash生成新的ssh key ssh-keygen -t rsa -C ...
- git 配置ssh key
第一次生成 ssh key 进入ssh目录 cd ~/.ssh,再输入:ls ,查看文件,如果有.pub的文件,说明已有ssh key 如果没有, 则生成秘钥:ssh-keygen -t rsa - ...
随机推荐
- 二十一、【.Net开源框架】EFW框架Web前端开发之目录结构和使用FireBug调试方法
回<[开源]EFW框架系列文章索引> EFW框架源代码下载V1.2:http://pan.baidu.com/s/1hcnuA EFW框架实例源代码下载:http://pan.baidu. ...
- Web API 入门系列 - RESTful API 设计指南
参考:https://developer.github.com/v3/ https://github.com/bolasblack/http-api-guide HTTP 协议 目前使用HTTP1. ...
- KIS旗舰版常用数据表
select * from IC_Web2ERPOrders --网上订单 FOrderStatus 14--已发货,6--待发货,2--待配货,1--未审核 (审核后变为2,进入待配货)sele ...
- 构造Lambda表达式
/// <summary> /// 构造Lambda表达式 /// </summary> /// <typeparam name="T">< ...
- Log4Net 手册
首先感慨下,现在的程序员做的工作因为高级语言的生产力,系统框架模式的成熟,开源大牛的贡献,已经成越来越偏向 “面向配置编程”了...... 详细使用指南见文章:http://blog.csdn.net ...
- 说说你所熟知的MSSQL中的substring函数
说说你所熟知的MSSQL中的substring函数 *:first-child { margin-top: 0 !important; } body>*:last-child { margin- ...
- [IR] Index Construction
Three steps to construct Inverted Index as following: 最难的step中: Token sequence. Sort by term. Dictio ...
- Javascript语法去控制Web控件的Enabled属性
Web控件当使用Enabled属性时,它生成html之后会变成了disabled了.我们为了能够在javascript去控制控件的禁用与启用,得从这个disabled入手.如:
- 在aspx怎么引用public string getPicurl(string picurl)?
刚才在论坛上看到一帖: Insus.NET尝试做了一下,直接使用一个Img标签是无法实现.因为函数中返回的即是一个img html标签,因此在aspx页再不能使用Img了. 现在可以回到网友的问题,那 ...
- Python入门笔记(26):Python执行环境
一.python特定的执行环境 在当前脚本继续进行 创建和管理子进程 执行外部命令或程序 执行需要输入的命令 通过网络来调用命令 执行命令来创建需要处理的输出 动态生成Python语句 导入Pytho ...