keywords: [github]设置免密码push时的相关问题

免密码push设置

1,先在本地生成ssh的公钥,方法如下:

https://gist.github.com/yisibl/8019693

2,在github自己的账号后台中添加上面生成的key,将id_rsa.pub中的所有内容全部copy过来即可。

添加key的页面:https://github.com/settings/keys

3,将https替换为ssh:

git remote set-url origin git@github.com:USERNAME/REPOSITORY.git 

4,将当前客户端的ssh链接添加到github信任列表

ssh -T git@github.com

如果不执行这个步骤,会push时会出现错误提示:

ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository

另外,执行此步骤时必须关掉爬墙工具(你懂的),否则会提示链接超时。

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

Git 在提交 代码时,报错:

ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

在连接 github 时,执行ssh -T git@github.com命令时,出现:

$ ssh -T git@github.com
ssh: connect to host github.com port 22: Connection timed out

在存放公钥私钥 (id_rsa 和 id_rsa.pub) 的同级文件夹中,新建 config 文本,内容如下:

Host github.com
User hellojue@foxmail.com
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

其中 User 为登录 github 的账号名称。
再次执行ssh -T git@github.com时,这时验证就可以通过:

$ ssh -T git@github.com
Hi Jueee! You've successfully authenticated, but GitHub does not provide shell access.

原文:ssh connect to host github.com port 22 Connection timed out - 小决的专栏