1 2 3 4 |
vi <span class="hljs-meta-keyword">/etc/</span>ssh/sshd_config <span class="hljs-meta">#Port 22 <span class="hljs-comment">//这行去掉#号,防止配置不好以后不能远程登录,还得去机房修改,等修改以后的端口能使用以后在注释掉</span></span> Port <span class="hljs-number">33378</span> <span class="hljs-comment">//下面添加这一行</span> |
firewall添加想要修改的ssh端口:
1 2 3 4 5 6 |
添加到防火墙: firewall-cmd <span class="hljs-comment">--zone=public --add-port=33378/tcp --permanent (permanent是保存配置,不然下次重启以后这次修改无效)</span> 重启: firewall-cmd <span class="hljs-comment">--reload</span> 查看添加端口是否成功,如果添加成功则会显示yes,否则no firewall-cmd <span class="hljs-comment">--zone=public --query-port=33378/tcp</span> |
使用以下命令查看当前SElinux 允许的ssh端口:
1 |
semanage port -l | <span class="hljs-keyword">grep</span> ssh |
添加33378端口到 SELinux
1 |
semanage port -a -t <span class="hljs-keyword">ssh_port_t</span> -p tcp <span class="hljs-number">33378</span> |
然后确认一下是否添加进去
1 |
semanage port -l | <span class="hljs-keyword">grep</span> ssh |
如果成功会输出
1 |
<span class="hljs-keyword">ssh_port_t</span> tcp <span class="hljs-number">33378</span>, <span class="hljs-number">22</span> |
1 |
<span class="hljs-selector-tag">systemctl</span> <span class="hljs-selector-tag">restart</span> <span class="hljs-selector-tag">sshd</span><span class="hljs-selector-class">.service</span> |
测试修改端口以后的ssh连接,如果成功则将step1里面的port 22 重新注释掉