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 ...
随机推荐
- Go语言AST尝试
Go语言有很多工具, goimports用于package的自动导入或者删除, golint用于检查源码中不符合Go coding style的地方, 比如全名,注释等. 还有其它工具如gorenam ...
- jQuery学习-事件之绑定事件(六)
在jQuery中,为了屏蔽event对象在各浏览器中的差异性,它使用了自定的Event对象,如下: 1 jQuery.Event = function( src, props ) { 2 ...
- 调用底层的viewController--返回底层
//返回底层viewController的方法-- - (UIViewController*)GetViewController:(UIView*)uView { for (UIView* next ...
- CC++初学者编程教程(8) VS2013配置编程助手与QT
1. 2. 配置编程助手 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26 ...
- C语言的本质(11)——指针与数组
1.指针数组和数组指针的内存布局 初学者总是分不出指针数组与数组指针的区别.其实很好理解:指针数组:首先它是一个数组,数组的元素都是指针,数组占多少个字节由数组本身决定.它是"储存指针的数组 ...
- C语言的本质(8)——副作用与顺序点
C 语言中,术语副作用是指对数据对象或者文件的修改.例如以下语句 var = 99; 的副作用是把 var 的值修改成 99.对表达式求值也可能产生副作用,例如: se = 100 对这个表达式求值所 ...
- 习题3.15 自调整表Find例程
#include<stdio.h> #include<stdlib.h> typedef int * List; /* 自调整表的Find数组实现 */ int Find(Li ...
- 关于 unity3d securityexception no valid crossdomain policy available 的错误解决方法
错误大概就是这样的,事实上我一直没有注意,好像是我转平台到webplayer的关系,就无法访问自己的服务器上面的东东了,现在怎么做呢? 在自己的服务器根目录(哪个是根目录不懂,可以去投胎了哈),创建一 ...
- [置顶] 与小伙伴共勉的java有关jvm的知识(一),小鸟尽量写得详细哦,欢迎讨论,谢绝喷子
JAVA运行在JVM之上,JVM的运行状况会对程序产生很大的影响,因此了解一些JVM的东东,对于编写稳定的,高性能的java程序至关重要.这是JVM的规范中定义的标准结构图: 以上标准是JVM标准中定 ...
- scp的使用
scp有两种版本 一种是ma的 直接使用scp命令 一种是winscp类似ftp mac版的scp命令格式如下: scp ./xxx.tar.gz root@ip: /root/xxx 这句话的意思是 ...