前置
已创建公钥私钥,并上传公钥到全球最大同性交友网站——GitHub
因为我生成公私钥的时候有使用密码,并且不想放弃,所以就没有使用其它的两种方法:1.使用https连接方式/2.更改ssh连接端口(嗯?不对,我好像就是这种)。嗯?不对,我好像不是。好像是又好像不是...
确定了,不是👻
另外,据说SSH速度更快,在某些情况下会用到。
错误发生
IO0288@IO0288-■■■■ MINGW64 ~/■■■■
git config --global user.name
IO0288
IO0288@IO0288-■■■■ MINGW64 ~/■■■■ git config --global user.email
admin@iabu.xyz
IO0288@IO0288-■■■■ MINGW64 ~/■■■■ (master)
$ git clone git@github.com:IO0288/WP-NewWorld.git
Cloning into 'WP-NewWorld'...
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
导致该情况发生的原因可能有很多种,大多数人犯的错误或许就是没有好好了解OpenSSH...包括我。
建议参考资料SSH_config,页面是英文的,建议配合翻译,或者直接搜索该关键词。
上傻瓜式解决方案
REM cmd命令提示符版本
%HOMEDRIVE%
cd %HOMEPATH%
cd .ssh
echo # Read more about SSH config files: https://linux.die.net/man/5/ssh_config> config
echo Host github.com>> config
echo User git>> config
echo Hostname ssh.github.com>> config
echo PreferredAuthentications publickey>> config
echo IdentityFile ~/.ssh/id_rsa>> config
echo # Port 443>> config
将以上代码放入CMD
运行即可,或者自己动手将一下内容放到C:/User/用户名/.ssh/config文件中...注意没有后缀。
# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
我的config文件
# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host 其它域名.com
HostName 其它域名.com
User root
#可以添加多个域名,user按实际来填写
Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
#使用公钥验证
IdentityFile ~/.ssh/id_rsa
#指定身份文件(私钥)
# Port 22
# Port 443
Port默认为22,亲测可省略。#是注释符
再次测试
(默认)port 22
IO0288@IO0288-■■■■ MINGW64 ~/Desktop/study_c/git
$ git clone git@github.com:IO0288/WP-NewWorld.git
Cloning into 'WP-NewWorld'...
The authenticity of host 'ssh.github.com (18.140.96.234)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'ssh.github.com' (RSA) to the list of known hosts.
Enter passphrase for key '/c/Users/ASUS/.ssh/id_rsa':
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), 12.50 KiB | 79.00 KiB/s, done.
其实也没什么好打码的,就是想打了..
port 443
IO0288@IO0288-■■■■ MINGW64 ~/Desktop/study_c/git
$ git clone git@github.com:IO0288/WP-NewWorld.git
Cloning into 'WP-NewWorld'...
The authenticity of host '[ssh.github.com]:443 ([18.141.90.153]:443)' can't be established.
RSA key fingerprint is SHA256:■■■■■■■.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '■■■■■■■' (RSA) to the list of known hosts.
Enter passphrase for key '■■■■■■■':
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), 12.50 KiB | 3.13 MiB/s, done.
目前来看最大的区别就是其中连接使用的端口,emm,诸君自己看着办吧。
Q.E.D.
Comments | NOTHING