Table of Contents
生成 ssh key
$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/Users/xxx/.ssh/id_rsa): github Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in github. Your public key has been saved in github.pub. The key fingerprint is: SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [email protected] The key's randomart image is: +---[RSA 2048]----+ |o. o . | |.oo=o.o . | |.oooo*.+. | |..+o=++oo. | |E +*+oo*S. | |.*= ....= | |++.o . | |+.+ | | =o | +----[SHA256]-----+
在 github 上面设置公钥。
配置 git config
编辑 .ssh
目录下的 config 文件。添加如下行
HOST github.com HostName github.com IdentityFile ~/.ssh/github
然后通过如下命令测试是否可用
ssh -T [email protected]
如果成功会返回如下信息
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
但是诡异的是我一直返回下面的错误
ssh: connect to host github.com port 22: Operation timed out
Google 之后发现了这里,有可能是防火墙禁用了 ssh 链接的问题导致的。所以按照文章所说,需要修改一下连接的端口号,通过 https 的443端口来进行。修改之后为如下形式
HOST github.com HostName ssh.github.com Port 443 IdentityFile ~/.ssh/github
配置某网段禁用公钥检查
HOST 10.235.*.* HostName %h Port 22 StrictHostKeyChecking no UserKnownHostsFile /dev/null
参考: