git ssh认证
一般新手用git时,使用HTTPS都需要输入用户名和密码,这是一个很低效的开发过程。(虽然有时可以让开发人员减少push的次数)。github提供了几种连接方式,其中以https:开头的代表https连接,以git开头代表ssh连接。所以用ssh连接时要确保
你客户端的版本库url设置的ssh的url,而不是https的url。如何查看客户端的连接设置,使用下面的命令:
$ git config --list
显示中有一个
remote.origin.url=xxxxxx
如果url不是git开头的,去项目网址复制下ssh地址,然后设置url为新的地址
$git config remote.origin.url 新地址
。
生成ssh的步骤官网有详细说明:https://help.github.com/articles/generating-ssh-keys
大概如下:
1.转到目录(如果没有.ssh,就创建一个,不能用普通创建文件夹方式创建以.开头的,用命令行)
$ cd ~/.ssh 这个在win7上无效,~代表用户目录,win7一般为:C:\Users\Administrator\.ssh (管理员身份登录) )
2. 生成key:
ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter]
ssh-add id_rsa (输入文件的名字,一般输入id_rsa就可以了) 然后会提示输入2次密码,(这里我们直接输入回车,不然以后每次都要输入密码,麻烦)输入完成后就在.ssh文件夹下面生成了2个文件:id_rsa和id_rsa.pub
把id_ras.pub内容复制下。 3.去Account Settings 新增一个key,key名字随意,Key内容就粘贴下刚才复制的就可以了。 4.测试
$ssh -T git@github.com (输入这个,千万注意,邮箱不要改)
# Attempts to ssh to github
You may see this warning:
# The authenticity of host 'github.com (207.97.227.239)' can't be established.
# RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
# Are you sure you want to continue connecting (yes/no)?
Don't worry, this is supposed to happen. Verify that the fingerprint matches the one here and type "yes".
# Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.
If that username is correct, you've successfully set up your SSH key. Don't worry about the shell access thing, you don't want that anyway.
遇到了几个错误:
permission denied,一般都会遇到这种错误,看官网说明:
https://help.github.com/articles/error-permission-denied-publickey
错误:Could not open a connection to your authentication agent.
解决方法】需要ssh-agent启动bash,或者说把bash挂到ssh-agent下面。
【具体方法】
islue@localhost $ ssh-agent bash --login -iislue@localhost $ ssh-add
(如果上面还是报错:
Could not open a connection to your authentication agent.则
http://funkaoshi.com/blog/could-not-open-a-connection-to-your-authentication-agent
SSH private-keys are usually stored encrypted on the computers they are stored on. A pass-phrase is used to decrypt them when they are to be used. Since most people use SSH public-private key-pairs to get around typing in passwords all the time, the ssh-agentdaemon exists to store decrypted private-keys you plan on using in a given session. The thing most people get tripped up on when using ssh-agent is that what the program outputs, some borne or csh shell commands, needs to be run. It may look like ssh-agent has set some variables for you, but it has in fact done no such thing. If you call ssh-add without processing ssh-agent’s output, it will complain it is unable to open a connection to your authentication agent. The most straightforward way to run ssh-agent on the command line is as follows: eval `ssh-agent`. After doing this, calls to ssh-add should succeed without error.
执行ssh-add ~/.ssh/rsa
报标题上的错误
先执行 eval `ssh-agent` (是~键上的那个`) 再执行 ssh-add ~/.ssh/rsa成功
ssh-add -l 就有新加的rsa了
)
【ssh-agent介绍】
ssh-agent就是一个管理私钥的代理,受管理的私钥通过ssh-add来添加,所以ssh-agent的客户端都可以共享使用这些私钥。
好处1:不用重复输入密码。
用 ssh-add 添加私钥时,如果私钥有密码的话,照例会被要求输入一次密码,在这之后ssh-agent可直接使用该私钥,无需再次密码认证。
好处2:不用到处部署私钥
假设私钥分别可以登录同一内网的主机 A 和主机 B,出于一些原因,不能直接登录 B。可以通过在 A 上部署私钥或者设置 PortForwarding 登录 B,也可以转发认证代理连接在 A 上面使用ssh-agent私钥登录 B。
islue@localhost $ ssh -A HOST_Aislue@HOST_A $ ssh HOST_B
islue@HOST_B $
ssh-add完后,可以用ssh-add -l来查看结果:
客户端第一次push会在.ssh生成一个known_hosts文件:
这样,以后就不用输入用户名和密码了。
如果出现:
git clone git@x.x.x.x:test.git
Permission denied (publickey,gssapi-with-mic).
fatal: The remote end hung up unexpectedly.
原因是没有起到ssh。
运行:
ssh-agent bash .
或者不从cmd运行,直接从git bash运行。
git ssh认证的更多相关文章
- 【jenkins】04.SSH认证方式拉取Git代码
首先需要会git ssh 我们一般用http的形式拉取代码. ssh的好处就是不用每次输入密码,而且貌似会快丢丢,不知道是不是错觉. 大概需要三个步骤: 一.本地生成密钥对: 二.设置github上的 ...
- git/ssh捋不清的几个问题
主要是 windows 用户会遇到很多纠结的问题,linux/unix 用户属于这方面的高端用户,应该有能力处理此类问题,而且网络上也有很多解决方案,本文的授众是 windows 用户.由于今天配置了 ...
- git: windows git ssh keys生成
http://blog.csdn.net/lsyz0021/article/details/52064829 当我们使用github或者bitbucket等仓库时我们有可能需要ssh认证,所以需要生成 ...
- GIT SSH免登录密码实现更新(git pull)、推送(git push)操作
一.使用场景 现在有两台服务器A和B,在A服务器上搭建有git版本代码仓库,现要实现B服务器SSH免密码登录A服务器,并能够从A服务器拉取.推送代码! 二.操作步骤 1.在B服务器项目根目录下执行以 ...
- Git 进阶指南(git ssh keys / reset / rebase / alias / tag / submodule )
在掌握了基础的 Git 使用 之后,可能会遇到一些常见的问题.以下是猫哥筛选总结的部分常见问题,分享给各位朋友,掌握了这些问题的中的要点之后,git 进阶也就完成了,它包含以下部分: 如何修改 ori ...
- ssh 认证指定端口
[root@database2 ~]# cat ssh.sh if [ ! $# -eq 2 ] ;then echo "请输入用户密码以空格分开" exit else ssh-k ...
- 批量的单向的ssh 认证
<pre name="code" class="python">if [ ! $# -eq 2 ] ;then echo "请输入用户密码 ...
- 如何生成git ssh key
公司有自己的git版本控制,自己注册账号后,管理员同意,就可以查看项目代码了,但是要克隆的话需要在本地生成git ssh key 一.进入.ssh文件夹. cd ~/.ssh 若没有.ssh文件夹,则 ...
- Git SSH公钥配置
https://www.cnblogs.com/smuxiaolei/p/7484678.html https://blog.csdn.net/weixin_42063071/article/deta ...
随机推荐
- css样式表中四种属性选择器
学习此连接的总结http://developer.51cto.com/art/201009/226158.htmcss样式表中四种属性选择器1> 简易属性 tag[class]{ font-we ...
- windows程序设计读书笔记4——字符显示3
在之前的一章里我们使用InvalidateRect函数,生成窗口重绘消息进行重绘,但是并没有在处理滚动条消息时直接绘制,这样的代码效率并不高. 这里作者使用了UpdateWindow函数,直接进行窗口 ...
- CSS自学笔记(10):CSS3盒子模型
CSS3为CSS技术的升级版本.最新版本. 就CSS而言,它是一个模块,是一个庞大而又复杂的模块,但是在CSS3中,将这一个庞大的模块分解为一个个容易理解的同时又很精简的小模块,同时CSS3中又添加了 ...
- docker 创建新的镜像到私有仓库
docker:/data# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bd6db4127a9e centos &q ...
- java中读取程序运行时间
第一种是以毫秒为单位计算的. Java代码 //伪代码 long startTime=System.currentTimeMillis(); //获取开始时间 doSomeThing(); // ...
- javascript 汉字拼音排序
定义和用法 用本地特定的顺序来比较两个字符串. 语法 stringObject.localeCompare(target) 参数 描述 target 要以本地特定的顺序与 stringObject 进 ...
- [11-2] adaboost理解
以二分类问题为例({-1,+1}) adaboost步骤: 1.初始化u1=(1/N,1/N,-,1/N) 2.找到h,使最小化,记该h为g:计算作为该g的权重 3.更新ui: 4.重复2,3得到T个 ...
- UVA 116 Unidirectional TSP 经典dp题
题意:找最短路,知道三种行走方式,给出图,求出一条从左边到右边的最短路,且字典序最小. 用dp记忆化搜索的思想来考虑是思路很清晰的,但是困难在如何求出字典序最小的路. 因为左边到右边的字典序最小就必须 ...
- Linux学习十八之、善用判断式
原文地址:http://vbird.dic.ksu.edu.tw/linux_basic/0340bashshell-scripts_3.php 善用判断式 在第十一章中,我们提到过 $? 这个变量所 ...
- Mysql两种存储引擎的优缺点
MyISAM引擎是一种非事务性的引擎,提供高速存储和检索,以及全文搜索能力,适合数据仓库等查询频繁的应用.MyISAM中,一个table实际保存为三个文件,.frm存储表定义,.MYD存储数据,.MY ...