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 ...
随机推荐
- .Net之垃圾回收算法
垃圾回收器检测托管堆中是否有应用程序不在使用的任何对象,如果一次垃圾回收之后,堆栈没有可用的内存,new操作符将会抛出OutOfMemoryException(内存溢出). 每一个应用程序都包含一组根 ...
- 自给自足:动手打造html5俄罗斯方块
时间:凌晨2:36 历时:两晚+半个下午 代码:约300行 这两天发烧,头痛脑壳昏的,没想到竟然还能有动力去做小游戏,其实这不是我第一次想要弄个俄罗斯方块,前几个星期的时候就尝试着去弄一个,然后被凌乱 ...
- contact表单错误解决记录
在上篇表单验证中,过程中可谓坎坷,记录一下错误问题及解决方案. 我们用到的模板contact_form.html如下,其他urls.py自行去修改. <html> <head> ...
- Best Financing(HD4833)
每笔收入产生的收益是独立的. 计算所有点的收益率,累计. #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<al ...
- HTTP生命周期
HTTP生命周期 Http 请求 AspNet_ISAIP.DLL (ISAPI扩展,独立于站点外,用于可扩展的桥梁), w3wp.exe (net工作进程) IIS6 以上,6以下为aspnet_w ...
- Delphi 服务操作
unit Service; interface uses Windows,Messages,SysUtils,Winsvc,Dialogs; function StartServices(Const ...
- 5.4const对象
常成员函数 一个const对象可以调用const函数,但不能调用非const成员函数.必须将关键字const放在函数参数表之后,才能说明该函数是一个const成员函数. 声明常成员函数的格式如下: 类 ...
- uva 10051 Tower of Cubes(DAG最长路)
题目连接:10051 - Tower of Cubes 题目大意:有n个正方体,从序号1~n, 对应的每个立方体的6个面分别有它的颜色(用数字给出),现在想要将立方体堆成塔,并且上面的立方体的序号要小 ...
- HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS)
HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS) http://acm.hdu.edu.cn/showproblem.php?pi ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...