📒
notebook
  • Notebook
  • DevOps
    • Git
      • 常见 Git 操作
      • 使用 SSH 连接 Git 远程仓库
      • 使用 GPG Keys 签名 Git 提交
      • Git on macOS
    • Docker
      • macOS 安装配置 Docker
      • CentOS7 安装配置 Docker CE
  • Linux
    • CentOS
      • CentOS7 安装配置 vsftpd
      • CentOS7 设置虚拟内存
      • CentOS7 使用 acme.sh 自动申请免费 SSL 证书
      • CentOS7 修改 SSH 端口号
      • CentOS7 主机初始设置
      • 阿里云 CentOS 主机常见设置
      • CentOS7 安装配置 SS
    • nginx
      • nginx 配置 301 永久重定向
      • nginx 使用 SSL证书配置 HTTPS
      • CentOS7 安装配置 nginx
      • nginx 配置 gzip 压缩
      • nginx 代理静态网页
  • Server
    • Ghost
      • macOS 安装配置 Ghost
      • CentOS7 安装配置 Ghost
    • npm & Yarn
      • Yarn 常用命令
      • CentOS7 安装卸载升级 Yarn
      • npm & Yarn 常见错误处理
      • macOS 安装卸载升级 Yarn
    • Node.js
      • Awesome Node.js
      • CentOS7 安装卸载升级 Node.js
      • macOS 安装卸载升级 Node.js
  • Web
    • Ionic
      • 创建 Ionic & Angular 项目
      • 使用 Ionic & Cordova 构建 Android 应用
      • macOS 搭建 Ionic & Cordova 开发环境
    • CSS
      • CSS 排版技巧
      • Awesome CSS
      • CSS 三栏自适应布局
    • Angular
      • Awesome Angular
      • 创建 Angular 项目
    • HTML
      • HTML head 常用标签
      • HTML 常用 DTD 声明
      • 常用网页语义结构
    • Web 技术标准
    • JavaScript
      • Awesome JavaScript
      • JavaScript 的 eval() 函数详解
  • Mobile
    • H5
      • iOS Safari Web App 配置
  • Development Environment
    • Development Utilities
      • Awesome Windows
      • macOS 安装配置 Homebrew
      • Awesome macOS
      • macOS 安装配置 iTerm2
    • FEED
      • 常用 Gulp 插件
  • Network
    • 常见公共 DNS
  • Technology Stacks for Web Front-End Development
Powered by GitBook
On this page
  • 修改配置文件
  • 防火墙设置
  • 登录测试

Was this helpful?

  1. Linux
  2. CentOS

CentOS7 修改 SSH 端口号

修改配置文件

打开 SSH 配置文件:

sudo vim /etc/ssh/sshd_config

找到 #Port 22 ,取消注释,修改端口号:

Port <port>

Tips: <port> 为新端口号,范围为 1024-65535(注意回避一些常用软件端口号)。

保存并退出,重启 SSH 服务:

sudo systemctl restart sshd

防火墙设置

查看默认区域永久配置:

sudo firewall-cmd --permanent --list-all

public target: default icmp-block-inversion: no interfaces: sources: services: ssh ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:

可见 services: ssh 表示 SSH 服务已启用,ports: 为空表示没有添加其他任何端口。

Tips:

如果未启用,可手动永久添加 SSH 服务到默认区域:

sudo firewall-cmd --permanent --add-service=ssh

如果 ports 中永久添加了 22/tcp ,则永久删除:

sudo firewall-cmd --permanent --remove-port=22/tcp

永久添加新的端口到 SSH 服务:

sudo firewall-cmd --permanent --service=ssh --add-port=<port>/tcp

从 SSH 服务永久移除默认的 22 端口:

sudo firewall-cmd --permanent --service=ssh --remove-port=22/tcp

重载防火墙规则:

sudo firewall-cmd --reload

Tips: 阿里云主机还需要在安全组规则或防火墙规则中添加入方向的 <port>/tcp 端口,并删除 22/tcp 端口。

登录测试

打开一个新的终端窗口,使用新端口登录:

ssh <user>@<ip> -p <port>

退出之前的 SSH 操作窗口:

exit
PreviousCentOS7 使用 acme.sh 自动申请免费 SSL 证书NextCentOS7 主机初始设置

Last updated 4 years ago

Was this helpful?