原因

出于安全原因,学校把22端口禁用了,使用校园网无法通过ssh(默认22端口)连接上github。


本文实现目标

0、不使用代理

1、在windows下,解决22端口无法连接到github

2、解决hexo无法上传到github问题


步骤

1、配置ssh的config

用记事本打开ssh连接用到的config文件,如果没有.ssh目录,请打开“隐藏的目录和文件”

路径:C:\Users\用户名\.ssh\config

代码如下,需要自行修改IdentityFile,其它的可以不变

1
2
3
4
5
Host github
HostName ssh.github.com
Port 443
User git
IdentityFile "C:\Users\用户名\.ssh\id_rsa"

相关解释

名称 解释
Host github 自定义的名称,方便给每个服务器设置一个方便记忆的名字,如:github.com或github
HostName ssh.github.com 必须为真实的域名或服务器ip,因为要用ssh连接到github,所以这里必须修改为ssh.github.com
Port 443 因为22端口被禁用,但可以使用https协议的443端口
User git 使用默认的用户名git
IdentityFile 私钥路径 github允许的私钥的路径,需要自行修改

2、连接github测试

打开git,输入

1
ssh -T git@github

注意

  • git是上面配置ssh的config的User
  • github是上面配置ssh的config的Host,其它网站的教程如果写github.com也是可以的,根据自己的配置文件变化

如果配置没问题,得到下图结果

image-20220530125034712

3、修改hexo配置文件

路径/hexo/_config.yml

找到配置的部分:

image-20220530125138674

注意:

  • 和第二步一样,gitgihub要分别对应配置ssh的config里面的内容

这个上传链接在github库可以找到

image-20220530125354290

4、hexo上传到github测试

输入代码进行部署

1
hexo d -g

结果如下图,成功

image-20220530125555315


附言

当然,开代理也可以解决上面所有问题,但必须为真全局代理(类似vpn的那种属于链路层的软件),不能是一般的ss或v2ray协议(属于传输层,只能代理应用层)。


参考

1、https://jshih.dev/2016/02/24/git-ssh-with-port-22-outbound-blocked.html

2、https://dj9399.github.io/post/HEXO提交报错-22端口连接超时/

其中,2里面提到,这个操作就是为了刷新config,使修改生效。

1
2
git config --global user.name "XXX"
git config --global user.email XXX@xx.com

在此粘贴下本博客的自定义css【原主题为butterfly】,本主题样式模仿Typora中的Drake主题

hexo/theme/butterfly/_config.yml文件中添加下面的代码

1
2
3
4
inject:
head:
# 添加自定义css
- <link rel="stylesheet" href="/mycss/lthero-css.css">

再在butterfly的source目录创建mycss目录,再将下面的css放在lthero-css.css文件中即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#article-container.post-content h1{
/* padding-left: 15px; */
text-align: center;
/* background-color: rgb(199,237,204); */
}
#article-container.post-content h2 {
padding-left: 15px;
border-left: solid;
border-color: rgb(128,0,32);
border-width: 5px;
}
#article-container.post-content h4,h5,h6 {
padding-left: 25px;
border-left: solid;
border-color: rgb(129,216,208);
border-width: 2px;
margin: 10px 0 10px;
}
strong{
color:#273849;
}
#article-container p {
/* color:#333333; */
color:#000000;
font-family:"Microsoft YaHei";
margin: 0 0 10px;
font-size: 18px;
}

#article-container code{
padding: 2px 4px;
background: #F7F7F7;
color: #D63200;
}
#aside-content .card-widget {
position: relative;
overflow: hidden;
margin-top: 20px;
padding: 20px 24px;
width: 390px;
}

#nav #site-name {
text-shadow: 2px 2px 4px rgb(0 0 0 / 15%);
font-weight: bold;
cursor: pointer;
font-size: 35px;
}
#nav #site-name:after {
display: inline;
content: '.';
color: rgb(250, 21, 89);
}
#page-header #site-title {
font-size: 4.85em;
}
#page-header #site-subtitle {
font-size: 2.12em;
}

#article-container ul li{
font-family:"Microsoft YaHei";
font-size: 18px;
}
#article-container ol li, #article-container ul li {
font-family:"Microsoft YaHei";
margin: 4px 0;
font-size: 18px;
}

blockquote {
margin: 0 0 16px;
padding: 10px 10px;
border-left: 5px solid #E95F59;
background-color: #fdefee;
color: black;
}

h2{
position: relative;
margin: 20px 0 14px;
font-size: 27px;
font-weight: bold;
color:#273849;
}
/* h3::before{
display: inline;
content: "# ";
} */
/* h4::before{
display: inline;
content: "## ";
} */
h3{
position: relative;
margin: 20px 0 14px;
/* color:#273849; */
color: var(--text-highlight-color);
font-weight: 600;
line-height: 1.6;
font-size: 23px;
}
h4{
position: relative;
margin: 14px 0 10px;
color: var(--text-highlight-color);
font-weight: 600;
line-height: 1.4;
font-size: 20px;
}
h5{
position: relative;
margin: 14px 0 10px;
color: var(--text-highlight-color);
line-height: 1.4;
font-size: 18px;
}
h6{
position: relative;
margin: 14px 0 10px;
color: var(--text-highlight-color);
line-height: 1.4;
font-size: 16px;
}