生成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

  1. 复制key到剪贴板

  2. 登录github
  3. 点击右上方的Accounting settings图标

  4. 选择 SSH key
  5. 点击 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
3

$ ssh -T -p 443 git@ssh.github.com
Hi username! You've successfully authenticated, but GitHub does not
provide shell access.

编辑SSH配置文件 ~/.ssh/config 如下:

2
3

测试是否配置成功

2
3

$ ssh -T git@github.com
Hi username! You've successfully authenticated, but GitHub does not
provide shell access.

 

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的更多相关文章

  1. git配置SSH Key,上传本地代码至github

    git配置全局的name和email git config --global user.name "name" git config --global user.email &qu ...

  2. Git配置SSH Key

    最近看到很多人在配置Git时,遇到很问题,网上教程千篇一律.这儿自己单独记录一份. Git配置SSH Key 1.检查本机是否有ssh key设置,切换到.ssh目录 $ cd ~/.ssh 或cd ...

  3. git生成ssh key及本地解决多个ssh key的问题

    git生成ssh key及本地解决多个ssh key的问题 ssh是一种网络协议,用于计算机之间的加密登录.ssh原理及应用可参考: SSH原理与运用(一):远程登录 生成ssh key步骤 这里以配 ...

  4. 一台电脑上配置多个git的ssh key

    前几天公司的代码库全部迁移到了阿里云上,在配置git的ssh key的时候遇到了一个问题,那就是自己的密钥在添加时提示已经存在,原来是自己的个人账号上已经添加过这个密钥了,公司分配的账号就不能再添加这 ...

  5. Git 中 SSH key 生成步骤

    由于本地Git仓库和GitHub仓库之间的传输是通过SSH加密的,所以必须要让github仓库认证你SSH key,在此之前,必须要生成SSH key. 第1步:创建SSH Key.在windows下 ...

  6. git 配置 .ssh key

    1.安装git软件: 2.打开本地git bash,使用如下命令生成ssh公钥和私钥对: ssh-keygen -t rsa -C 'xxx@xxx.com'    然后一路回车(-C 参数是你的邮箱 ...

  7. Git 生成SSH Key

    背景:服务器是LINUX系统(centos7),使用GitLab管理git代码库.各个客户端通过sourcetree 工具,采用SSH获取.提交代码.使用SSH的方式需要公钥和私钥.下面介绍秘钥的生成 ...

  8. git生成ssh key步骤并添加到github网站

    0: 查看是否已经有了ssh密钥 执行命令:cd ~/.ssh 如果没有密钥则不会有此文件夹,有则备份删除 1:使用 Git Bash生成新的ssh key ssh-keygen -t rsa -C  ...

  9. git 配置ssh key

    第一次生成 ssh key 进入ssh目录  cd ~/.ssh,再输入:ls ,查看文件,如果有.pub的文件,说明已有ssh key 如果没有, 则生成秘钥:ssh-keygen -t rsa - ...

随机推荐

  1. oracle 语句创建表空间、用户、授权

    /*分为四步 */ /*第1步:创建临时表空间 */ create temporary tablespace yuhang_temp tempfile 'D:\oracledata\yuhang_te ...

  2. SSH: 本地.ssh目录下的公钥文件最好删掉

    这次ssh amazon ec2的instance,在家里电脑登录OK,到了公司电脑登录失败(只支持公钥机制).私钥已经拷贝到公司的ubuntu上了,奇怪. 后来发现是.ssh目录下存在一些公钥文件导 ...

  3. 深入研究 蒋金楠(Artech)老师的 MiniMvc(迷你 MVC),看看 MVC 内部到底是如何运行的

    前言 跟我一起顺藤摸瓜剖析 Artech 老师的 MiniMVC 是如何运行的,了解它,我们就大体了解 ASP.NET MVC 是如何运行的了.既然是“顺藤摸瓜”,那我们就按照 ASP.NET 的执行 ...

  4. 爬虫技术 -- 进阶学习(八)模拟简单浏览器(附c#代码)

    由于最近在做毕业设计,需要用到一些简单的浏览器功能,于是学习了一下,顺便写篇博客~~大牛请勿喷,菜鸟练练手~ 实现界面如下:(简单朴素版@_@||) button_go实现如下: private vo ...

  5. node.js JS对象和JSON字符串之间的转换

    JSON.stringify(obj)将JS对象转为字符串. var json = { aa: ['sdddssd'],   bb: [ '892394829342394792399', '23894 ...

  6. 字符串js编码转换成实体html编码的方法(防范XSS攻击)

    js代码在html页面中转换成实体html编码的方法一: <!DOCTYPE html><html> <head>    <title>js代码转换成实 ...

  7. Android 学习笔记之AndBase框架学习(六) PullToRefrech 下拉刷新的实现

    PS:Struggle for a better future 学习内容: 1.PullToRefrech下拉刷新的实现...   不得不说AndBase这个开源框架确实是非常的强大..把大部分的东西 ...

  8. Sprint总结

    # Sprint 1 总结 > Sprint 1 主要是界面设计 > 为了遵循Material design,实际操作中依然遇到许多困难 > 预计耗时两小时每天,但是因为网络问题工作 ...

  9. 第一个sprint总结和读后感

    总结:通过第一个sprint的冲刺,了解了sprint的整个流程,学会了在一个团队里该如何开展一个项目和分配任务.我们的队团在第一个sprint中没有达到我们预期的效果,我们也做出了反省,原因一是我们 ...

  10. MIUI选项框开关样式模拟

    有IOS的开关模拟,当然也有MIUI的开关模拟 看到设置选项里面的开关样式,突发奇想地来试试    最终效果如图: 实现过程 1. 选项框checkbox 模拟开关当然需要一个选项框,这里用到了复选框 ...