GIT设置SSH公钥

来源:互联网 发布:mac上能玩哪些网络游戏 编辑:程序博客网 时间:2024/06/05 16:14

使用Git,一般可以使用http/https或者ssh连接。

使用http/https连接不需要额外的配置,但是如果工程中有一些比较大的文件,在push的时候经常会出现fatal: The remote end hung up unexpectedly的错误。

解决的办法是切换成使用ssh连接。这需要配置一个ssh公钥。步骤如下

1)进入$HOME/.ssh目录。如果没有创建过ssh密钥,目录为空。

$ cd ~/.ssh
$ ls

2)使用你的邮箱用ssh-keygen命令创建密码对。

$ ssh-keygen -t rsa -C "yourname@hotmail.com"

注意ssh-keygen命令中间没有空格,如果在ssh后面加上空格,会得到Bad escape character 'ygen'.的错误。


3)把公钥文件id_rsa.pub导入到git工程的公钥列表中

$ ls
github_rsa  github_rsa.pub  id_rsa  id_rsa.pub


4)把remote地址改成ssh。

$ git remote remove origin
$ git remote add origin git@***.git
$ git branch -u origin/master master
$ git remote -v