本地Git仓库和github仓库之间的传输是经过SSH加密传输的git
ssh-keygen -t rsa -b 4096 -C "youremail@example.com"
宿主目录 /用户/username/.ssh/目录下,会生产 id_rsa.pub(公钥) 和id_rsa(密钥) 两个文件github
ssh-agent
是一个密钥管理器。运行ssh-agent之后,使用ssh-add
将私钥交给ssh-agent
保管,其余程序须要身份验证的时候能够将验证申请交给ssh-agent
来完成整个认证过程。shell
# eval `ssh-agent -s` :启动代理,直接启动一个 ssh-agent 进程 eval `ssh-agent -s` #这里是反引号 ssh-add –l
登陆github,打开”settings”中的SSH Keys页面,而后点击“Add SSH Key”,填上任意title,在Key文本框里黏贴id_rsa.pub文件的内容。ssh
如: error: The requested URL returned error: 403 Forbidden while accessing测试
能够看见多是权限问题致使fetch
解决方法:加密
能够修改.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,修改完了保存
输入命令:进行测试url
ssh git@github.com
可能报错:代理
The authenticity of host 'github.com (192.30.252.131)' 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)? yes #这里写 yes Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of known hosts. Permission denied (publickey).
说是主机密钥验证失败, 发现是缺乏了 known_hosts 文件, 并且必须生成 github.com 的ip执行内容.code
缘由:可能使用的https 方法,而非 shell方式
解决方式:查看远程仓库信息
git remote -v origin https://github.com/yuquan0821/demo.git (fetch) origin https://github.com/yuquan0821/demo.git (push)
把https换成shell方式
git remote rm origin git remote add origin git@github.com:yuquan0821/demo.git git push origin `` - 问题4: 推送时报邮箱错误 错误信息:remote: error: GH007: Your push would publish a private email address. 解决方法:在GitHub的你帐号网页上右上角,我的的登陆退出的位置,找到setting: setting->emails->Keep my email address private,把这一项去掉勾选便可。