Blogger Information
Blog 110
fans 0
comment 0
visits 112242
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Linux系统-CentOS7 修改默认SSH端口
Coco
Original
928 people have browsed it

  SSH默认监听端口22,但是服务器开放到公网会经常被暴力登录,所以还是改下端口为好。

  Step1. 修改/etc/ssh/sshd_config,添加ssh端口

  #vi /etc/ssh/sshd_config

  找到行 #Port 22,取消注释,并添加自定义的ssh端口,假设111111端口(取10000~65535,一万以下可能被系统占用) Port 22 Port 111111

  保留22端口是以防万一,万一端口新增失败,22端口还是能用的,大不了用回22端口上服务器重新设置。

  Step2.设置SELinux (不想开启忽略这一步)

  检查selinux状态 #sestatus ;

  如果关闭,#vi /etc/selinux/config设置SELINUX=enforcing

  semanage port -l|grep ssh 查看ssh端口,

  如果没有装semanage,#yum install policycoreutils-python

  执行开放111111端口

  #semanage port -a -t ssh_port_t -p tcp 111111

  Step3.防火墙开放端口

  检查防火墙状态:#systemctl status firewalld ,没开就启动 #systemctl start firewalld

  添加端口: #firewall-cmd --add-port=111111/tcp --permanent

  重新加载: #firewall--cmd --reload

  Step4.重启

  重启ssh:#systemctl restart sshd

  重启firewalld:#systemctl restart firewalld

  重启计算机:#shutdown -r now

  Step5.尝试新端口登录

  ssh工具尝试连接,连接时,端口更改成新设置的111111,成功就可以继续了

  Step6.修改/etc/ssh/sshd_config,取消22端口并重启相关服务

  #vi /etc/ssh/sshd_config

  注释22端口: #Port 22

  重启ssh:#systemctl restart ssh

  完成后尝试22端口登录,会提示失败

  Tips:可以通过以下方式查看登录情况:

  last 命令 #last查看日志文件 /var/log/secure #cat /var/log/secure

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post