生成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. PostgreSQL和Greenplum、Npgsql

    PostgreSQL和Greenplum.Npgsql 想着要不要写,两个原因“懒”和“空”.其实懒和空也是有联系的,不是因为懒的写,而是因为对PostgreSQL和Npgsql的知识了解匮乏,也就懒 ...

  2. android.support.v4包中的LruCache源码简读

    package android.util; import java.util.LinkedHashMap; import java.util.Map; /** * A cache that holds ...

  3. IE代理文件自动设置

    想如果代理可用就使用代理,代理不可用就直接连接网络. 新建文件放入javascript代码,保存为proxy.pac,保存路径c:\proxy.pac function FindProxyForURL ...

  4. ruby 除法运算

    在Ruby中根据运算对象的值的不同进行不同的操作.除法运算符"/"的两边同为Interger对象时运算符进行整除运算,其中任意一方为Float对象时进行实数的除法运算. 7 / 2 ...

  5. `cocos2dx非完整` 添加xxtea加密模块

    在上一篇文章中,我已经开始着手写自己的模块,也就是fw部分.其中上一篇文章中完成的是lua部分的配置解析部分,涉及一点点平台方面的封装.这一片文章我来说明一下我是如何处理cocos2dx资源加密的.首 ...

  6. RESTful API 设计指南【转】

    网络应用程序,分为前端和后端两个部分.当前的发展趋势,就是前端设备层出不穷(手机.平板.桌面电脑.其他专用设备......). 因此,必须有一种统一的机制,方便不同的前端设备与后端进行通信.这导致AP ...

  7. SecureCRT rz 上传文件失败问题

    在把Windows上的文件传至Linux端时用到SecureCRT,一般小文件都没有问题,文件太大时则出现了上传后的文件只有几K大小,当然大于2个G的是不可能传的上去的了.对于几百M到1G多的大文件要 ...

  8. ios录制测试

    http://support.smartbear.com/viewarticle/64016/

  9. python——第二天

    类和实例: 创建实例是通过类名+()实现 但是!可以自由地给每个实例变量绑定新的属性(特指以前在类定义中没有的属性) __init__方法用来给类定义必要的几个属性,第一个参数永远是self type ...

  10. HTML简明教程(二)

    HTML简明教程(二) 一.HTML 图像 二.HTML 表格 三.HTML 列表 四.HTML div和 span 五.HTML 布局 六.HTML 表单和输入 七.HTML 框架 八.HTML内联 ...