Git使用ssh拉取Github代码问题
小于 1 分钟
Git使用ssh拉取Github代码问题
当配置了ssh后,拉取代码还是不成功,命令行出现如下代码
Cloning into 'vuepress-theme-hope'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
这里的22端口限制使用,所以这个时候需要使用443端口
在.ssh文件夹中手动创建config文件或者输入命令touch config
生成,并按下面的模板填写,该文件用于配置私钥对应的服务器。
Host github.com
HostName ssh.github.com # 这是最重要的部分
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
配置说明:
- Host:自定义别名,会影响git相关命令
- HostName:真实的服务器地址(域名)
- User:之前配置的用户名可以省略(xxx@xxx.com)
- Port:请求端口,当默认的22访问超限时,可以换个端口再尝试获取代码
- PreferredAuthentications:权限认证(publickey,password publickey,keyboard-interactive)一般直接设为publickey
- IdentityFile:rsa文件地址