ssh Git 初始配置及常见问题

2020-01-19  本文已影响0人  果蝇的小翅膀

1.添加用户名

git config --global user.name "XXX"

2.添加邮箱

git config --global user.email "XXX@XXX"

3.生成 ssh keys

ssh-keygen -t rsa -C "XXX@XXX" 

4.添加ssh keys 到你的github账号下

将 ~/.ssh/id_rsa.pub 里面的内容复制下来,选择你的github账号下的 Settings - SSH and CPG keys添加你的 ssh-keys

5.检查git的配置

ssh -T git@ssh.github.com

如果出现 “Hi qingjian1991! You've successfully authenticated, but GitHub does not provide shell access.”,说明ssh 配置成功

6.常见的错误

6.1 git不能下载库文件

git clone git@github.com:qingjian1991/THindex.git

Cloning into 'THindex'...

ssh: connect to host github.com port 22: Connection timed out

fatal: Could not read from remote repository.

Please make sure you have the correct access rights

and the repository exists.

解决方案:设置正确的git的端口

在 ~/.ssh下面新建一个文件 config,添加一下内容

Host github.com

  Hostname ssh.github.com

  Port 443

退出后修改文件的权限

chmod 600 ~/.ssh/config

这样就完成配置了。

上一篇下一篇

猜你喜欢

热点阅读