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 - ...
随机推荐
- cron语法
最近在搞whenever时看到可以用cron语法设置定时任务.所以研究了下cron 语法. every '0 0 27-31 * *' do command "echo 'you can u ...
- Python--matplotlib绘图可视化知识点整理
from:https://segmentfault.com/a/1190000005104723 本文作为学习过程中对matplotlib一些常用知识点的整理,方便查找. 强烈推荐ipython无论你 ...
- linux 硬盘分区,分区,删除分区,格式化,挂载,卸载笔记
linux 虽然一直都有在玩,但是对硬盘操作确实不是很熟悉今天有空,就整理了下. 1, 创建分区 先查看下是否有磁盘没有分区 fdisk -l 其中第一个框和第二个框,是已经分好区的磁盘,第三个硬盘没 ...
- JavaScript的深拷贝的实现
JavaScript的数据类型 简单数据类型 string number boolean function null undefined 复杂数据类型 String Number Boolean Fu ...
- 编写高质量JS代码的68个有效方法(五)
No.21.使用apply方法通过不同数量的参数调用函数 Tips: 使用apply方法自定一个可计算的参数数组来调用可变参数的函数 使用apply方法的第一个参数给可变参数的方法提供一个接收者 // ...
- 说说你所熟知的MSSQL中的substring函数
说说你所熟知的MSSQL中的substring函数 *:first-child { margin-top: 0 !important; } body>*:last-child { margin- ...
- 斐波那契堆(二)之 C++的实现
概要 上一章介绍了斐波那契堆的基本概念,并通过C语言实现了斐波那契堆.本章是斐波那契堆的C++实现. 目录1. 斐波那契堆的介绍2. 斐波那契堆的基本操作3. 斐波那契堆的C++实现(完整源码)4. ...
- read和write函数
读函数read ssize_t read(int fd,void *buf,size_t nbyte) 如果是ECONNREST表示网络连接出了问题. 写函数write ssize_t writ ...
- selenium webdriver (python) 第二版
前言 对于大多软件测试人员来讲缺乏编程经验(指项目开发经验,大学的C 语言算很基础的编程知识)一直是难以逾越的鸿沟,并不是说测试比开发人员智商低,是国内的大多测试岗位是功能测试为主,在工作时间中,我们 ...
- IT人的自我导向型学习:开篇杂谈
报考大学时,家人让我报的是计算机系,那个时候,普遍都认为读计算机专业的人将来不用愁找不到工作.为何得出这样的结论不得而知,但是在过去三十年中,的确有很多响当当赚了大钱的IT人在影响着我们. 顺利的考取 ...