网站首页 > 博客文章 正文
创建本地仓库与github的传输
这里假设你的仓库地址为/user/test.git,email地址为youremail@example.com,使用的时候替换成你自己的地址即可。首先注册github帐号,由于你的本地Git仓库和github仓库之间的传输是通过SSH加密的,所以需要使用ssh key:
1)创建SSH Key。在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件,如果有的话,直接跳过此如下命令,如果没有的话,打开命令行,输入如下命令:
# ssh-keygen -t rsa -b 4096 -C "youremail@example.com"
id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。
2)通过ssh-agent来管理密钥
这里我们通过ssh-agent来管理密钥,ssh-agent是一个密钥管理器,运行ssh-agent以后,使用ssh-add将私钥交给ssh-agent保管,其他程序需要身份验证的时候可以将验证申请交给ssh-agent来完成整个认证过程。
# eval "$(ssh-agent -s)"
# ssh-add –l
4096 7d:8c:84:86:95:ce:47:29:d4:9b:39:8e:28:0c:62:c9 /root/.ssh/id_rsa (RSA)
3)登录github,打开”settings”中的SSH Keys页面,然后点击“Add SSH Key”,填上任意title,在Key文本框里黏贴id_rsa.pub文件的内容。
同步仓库并解决403报错
这时候对本地仓库和github进行同步
# git push -u origin master
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/user/test.git/info/refs
fatal: HTTP request failed
提示403 Forbidden!
打开开关看详细日志
# export GIT_CURL_VERBOSE=1
# git push
* Couldn't find host github.com in the .netrc file; using defaults
* About to connect to github.com port 443 (#0)
* Trying 192.30.253.112... * Connected to github.com (192.30.253.112) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
* subject: CN=github.com,O="GitHub, Inc.",L=San Francisco,ST=California,C=US,postalCode=94107,STREET="88 Colin P Kelly, Jr Street",serialNumber=5157550,incorporationState=Delaware,incorporationCountry=US,businessCategory=Private Organization
* start date: Mar 10 00:00:00 2016 GMT
* expire date: May 17 12:00:00 2018 GMT
* common name: github.com
* issuer: CN=DigiCert SHA2 Extended Validation Server CA,OU=www.digicert.com,O=DigiCert Inc,C=US
> GET /user/test.git/info/refs?service=git-receive-pack HTTP/1.1
User-Agent: git/1.7.1
Host: github.com
Accept: */*
Pragma: no-cache
* The requested URL returned error: 401 Authorization Required
* Closing connection #0
> GET /user/test.git/info/refs HTTP/1.1
* The requested URL returned error: 403 Forbidden
可以看到上面红色加粗的文字(The requested URL returned error: 401 Authorization Required),是权限问题导致的,可以修改.git/config文件追加用户名和密码:
1)编辑.git/config文件
2)在[remote “origin”]下找到找到url变量
3)修改url = https://github.com/user/test.git,修改为url = ssh://git@github.com/user/test.git,修改完了保存
4)通过git push origin master进行同步,已经可以成功了
猜你喜欢
- 2024-10-10 Nutch-Hadoop-MongoDB搭建分布式爬虫
- 2024-10-10 OpenSSH更新至8.0,修复存在35年的安全漏洞
- 2024-10-10 [python] 基于paramiko库操作远程服务器
- 2024-10-10 利用Zabbix监控系统SSH方式检测远程目标主机
- 2024-10-10 手工方式IPSec VPN配置保障单位与分支之间的数据安全
- 2024-10-10 SSH 简介:安全远程访问的利器(安全远程登录协议ssh)
- 2024-10-10 [ Laravel 5.6 文档 ] 快速入门 —— 重量级开发环境:Homestead
- 2024-10-10 快速上手:Docker环境下的WordPress安装全攻略
- 2024-10-10 阿里云服务器Centos7.3安装Git(阿里云服务器centos装桌面)
- 2024-10-10 如何使用ssh密钥登录远程服务器(如何使用ssh密钥登录远程服务器账号)
你 发表评论:
欢迎- 367℃用AI Agent治理微服务的复杂性问题|QCon
- 358℃初次使用IntelliJ IDEA新建Maven项目
- 357℃手把手教程「JavaWeb」优雅的SpringMvc+Mybatis整合之路
- 351℃Maven技术方案最全手册(mavena)
- 348℃安利Touch Bar 专属应用,让闲置的Touch Bar活跃起来!
- 346℃InfoQ 2024 年趋势报告:架构篇(infoq+2024+年趋势报告:架构篇分析)
- 345℃IntelliJ IDEA 2018版本和2022版本创建 Maven 项目对比
- 342℃从头搭建 IntelliJ IDEA 环境(intellij idea建包)
- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)