Git如何使用ssh key连接到自己的GitHub账户/Git如何设置socks5代理

作者: 站长 上传时间: 浏览: N/A 下载: N/A 格式: N/A 评分: N/A

一、创建ssh key的私匙和公匙,并在github中添加公匙

方法一,直接使用git bash来创建
打开Git Bash。
粘贴以下命令,替换为您的GitHub电子邮件地址。
ssh-keygen -t rsa -b 4096 -C "[email protected]"
使用提供的电子邮件作为标签,这将创建一个新的ssh密钥。
Generating public/private rsa key pair.
当提示您“输入要在其中保存密钥的文件”时,请按Enter。存放在默认文件位置。
Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[回车确认保存位置]
在提示符下,键入安全密码。
Enter passphrase (empty for no passphrase): [输入你ssh key保护密码]
Enter same passphrase again: [再次输入你ssh key保护密码]

方法二、使用已有的ssh key来创建
你首先需要有私匙和公匙(例如以前使用putty工具、或其他工具创建的私匙和公匙)
然后在你git的默认目录(一般为C:\Users\Administrator)下创建一个文件夹githubssh
如下图所示

然后将你已有的私匙文件复制粘贴到该文件夹下(可以将其重命名为github_rsa),如下图所示

接着,登录你的github.com账户,进入https://github.com/settings/keys页面,点击“New SSH Key”

然后使用notepad++ 或记事本打开你的公匙文件(pub文件),将公匙内容粘贴到如下图步骤2位置

二、将私匙添加到当前git中
eval $(ssh-agent -s)
ssh-add ~/githubssh/github_rsa
Enter passphrase for /c/Users/Administrator/githubssh/github_rsa:[输入你ssh key保护密码]
成功则会显示如下:
Identity added: /c/Users/Administrator/githubssh/github_rsa (/c/Users/Administrator/githubssh/github_rsa)

然后测试一下是否能连接到github
ssh -T [email protected]
如果成功会显示如下:

三、如何给git设置代理(127.0.0.1本地代理)–国内访问github太慢,建议使用代理,至于代理怎么来…
查看本地git配置信息
git config --global -e
:q!
退出

git设置socks5代理
git config --global http.proxy 'socks5://127.0.0.1:梯子的端口'

git取消代理设置
git config --global --unset http.proxy

SSL错误提示
[cc]fatal: unable to access ‘https://github.com/xxxxxx/xxxxxxxx.git/’: error setting certificate verify locations:
CAfile: /mingw64/ssl/certs/ca-bundle.crt
CApath: none[/cc]
解决方法,重新设置SSL
[cc]git config –system http.sslcainfo D:\Program Files\Git\mingw64\ssl\certs\ca-bundle.crt[/cc]

使用
首先使用 git clone 下载github项目
然后修改完成后
[cc]git remote set-url origin github的仓库地址
git init[/cc]

然后合并提交
[cc]git commit -am “修改说明”

git push[/cc]

Leave a Comment