配置github公钥实现无密提交代码
来源:互联网 发布:东方时尚网络授课手机 编辑:程序博客网 时间:2024/06/05 00:48
git常用命令如下:
git clone git@github.com:yourname/repo.git //从github上克隆项目到本地
git add filename //将新增或者修改的文件添加到要提交的列表
git commit -m "add or modify file" //提交并注释
git push origin master //提交本地修改到主分支
最后两个命令其实就是我们在eclipse里面通过项目->右键->Team->commit选择文件之后进行的commit&push操作。
我们本地安装了git命令之后,可以从github上clone下来项目,如果对项目做了更改,还可以提交到项目中。但是如果默认无配置提交,需要我们输入github用户名密码。为了实现免密提交,我们需要配置github公钥(公钥没有限制可以针对不同的机器配置多个)。配置公钥可以分为以下三步。
第一步、生成密钥
第二步、将生成的密钥配置到github的https://github.com/settings/keys
密钥的内容就是根目录下.ssh/id_rsa.pub的内容,我们可以将其拷贝到key的位置,title可以随便填写。
通过如下命令来验证是否配置成功:
$ ssh -T git@github.com
以上操作表明我们本地到github上可以实现无需输入用户名密码就可以提交文件。但是实际我们再来提交代码时仍然提示需要输入用户名密码,这是怎么回事?
[root@client css]# git push origin masterUsername for 'https://github.com': yangfei2013Password for 'https://yangfei2013@github.com': remote: Invalid username or password.fatal: Authentication failed for 'https://github.com/yangfei2013/ghblog.git/'
原来git提交有两个地址一个是https://github.com/yourname/repo.git,还有一个地址是git@github.com:yourname/repo.git,如果我们配置了公钥,那么再提交代码时需要使用git@github.com:yourname/repo.git的url来提交。这样就需要我们配置这个提交的URL地址,没有修改配置之前我们通过 git config --list可以看到相关配置。
[root@client css]# git config --listuser.name=yangfei2013user.email=yangfei5459@126.comcore.repositoryformatversion=0core.filemode=truecore.bare=falsecore.logallrefupdates=trueremote.origin.url=https://github.com/yangfei2013/ghblog.gitremote.origin.fetch=+refs/heads/*:refs/remotes/origin/*branch.master.remote=originbranch.master.merge=refs/heads/master
第三步、配置提交的URL,更改项目路径下.git/config文件,修改remote.origin.url
更改之后,我们再通过git config --list查看remote.origin.url确实发生了变化
更改之后再次提交代码,就不出现提示输入用户名和密码了。
[root@client css]# vi ../.git/config [root@client css]# git push origin masterWarning: Permanently added the RSA host key for IP address '192.30.255.112' to the list of known hosts.Counting objects: 7, done.Compressing objects: 100% (3/3), done.Writing objects: 100% (4/4), 358 bytes | 0 bytes/s, done.Total 4 (delta 2), reused 0 (delta 0)remote: Resolving deltas: 100% (2/2), completed with 2 local objects.To git@github.com:yangfei2013/ghblog.git 8dd24e8..3fb9ab9 master -> master
- 配置github公钥实现无密提交代码
- 【图说】【Elipse配置git】实现github免密登录&提交项目到github
- Github如何提交代码
- github 提交代码 方法
- 使用github提交代码
- github上提交代码
- GitHub提交代码
- github提交代码使用
- github 提交代码 方法
- 提交代码到github
- Github提交代码方法
- github提交本地代码
- 利用Github提交代码
- 向Github提交代码
- 向GitHub 提交代码
- GitHub代码提交过程
- github 提交代码方法
- Github提交代码方法
- 常用基本Linux命令行(附图)
- 大数据教程(五)—— Hadoop集群MYSQL的安装
- swift 根据文字自动计算Label大小
- 搜狗拼字--疑难杂字的快速输入
- BOM之navigator对象和用户代理检测
- 配置github公钥实现无密提交代码
- 在FFMPEG中新增Filter
- C# 判断Socket断线重连
- Android hdpi ldpi mdpi xhdpi xxhdpi适配详解
- Android Studio解决unspecified on project app resolves to an APK archive which is not supported
- 《FreeSWITCH: VoIP实战》:嵌入式脚本
- java日期与字符串转换
- 冒泡、插入排序的比较
- JVM调优总结 + jstat 分析