当前位置:   article > 正文

Centos修改默认端口22_centos修改22默认端口

centos修改22默认端口

修改Centos服务器ssh链接的默认端口22到任意端口,主要两个步骤:

  1. 修改配置文件,添加端口
  2. 开放防火墙

一、

vim /etc/ssh/sshd_config
在文件中 #Port 22 行下增加
# Port 22 
Port [修改后端口]`
  • 1
  • 2
  • 3
  • 4

在这里插入图片描述

注意: 这里 先将其中的#Port 22前的#号去掉,然后在下面新增Port 你的端口,为什么这里先保留22,是要防止新的端口没有修改成功,还可以使用22端口进行连接。

二、开放防火墙

  1. 如果有firewall,那么运行指令:
firewall-cmd --zone=public --add-port=你的端口/tcp --permanent

firewall-cmd --reload
  • 1
  • 2
  • 3
  1. 重启ssh服务:
systemctl restart sshd.service

  • 1
  • 2
  • 重置时出现以下异常
Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.
  • 1

在这里插入图片描述
执行 “journalctl -xe” , 提示没有权限


2月 24 10:15:49 localhost.localdomain sshd[25045]: error: Bind to port 2022 on 0.0.0.0 failed: Permission denied.
2月 24 10:15:49 localhost.localdomain sshd[25045]: error: Bind to port 2022 on :: failed: Permission denied.
2月 24 10:15:49 localhost.localdomain sshd[25045]: fatal: Cannot bind any address.
2月 24 10:15:49 localhost.localdomain systemd[1]: sshd.service: main process exited, code=exited, status=255/n/a
2月 24 10:15:49 localhost.localdomain systemd[1]: Failed to start OpenSSH server daemon.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

在这里插入图片描述
3. 关闭 selinux
执行

setenforce 0  
  • 1

然后执行重置命令

systemctl restart sshd.service
  • 1

再查看

systemctl status sshd
  • 1
成功后修改回
setenforce 1 
  • 1
4. 如端口不通 请检查
  • 服务器防火墙是否开放端口
  • 安全组是否配置正确

三、测试新端口

telnet 192.168.21.12 2022 
  • 1
成功

四、最后,可以注释掉22端口

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/960289
推荐阅读
相关标签
  

闽ICP备14008679号