How to Change SSH Port on CentOS 7, 8 and 9

2023-11-15

The default SSH service port value is 22, in which case hackers may be able to launch attacks on the server through port 22, gain control of it or cause irreparable damage to it. To increase security of your server, you must change the default SSH port. In this article, you will learn How to Change SSH Port on CentOS 7 , 8 and 9. If you want to purchase CentOS VPS server, you can check the offered packages on Eldernode website.

Table of Contents

Tutorial Change SSH Port on CentOS 7 , 8 and 9

Recommended Article: How to check Linux kernel version on VPS

Introduction to SSH Port

SSH is a remote management protocol that allows users to remotely control and modify their servers. This service is an alternative to Telnet, which uses cryptographic techniques, unlike Telnet. It provides a mechanism for remote user authentication, data transfer from client to host and retransmission to client. Follow the steps below to change SSH port on CentOS. In this state, the port to be set needs to be re-tagged so that the access control policy rules can accept the SSH service for connection.

In the next section, we will teach you step by step how to Change SSH Port on CentOS 7 and 8.

Change SSH Port on CentOS 7 and 8

First login to your CentOS system and run the following command to backup your SSH configuration file:

date_format=`date +%Y_%m_%d:%H:%M:%S`  
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_$date_format

Then confirm the backup with the command below:

ls /etc/ssh/sshd_config*  
/etc/ssh/sshd_config /etc/ssh/sshd_config_2019_09_05:21:40:10

You can open SSH configuration file with any type of text editor (vi, vim, nano e.t.c):

sudo vi /etc/ssh/sshd_config

Find the line for port 22 and uncomment it and set your new service port to use; For example I use port 9782:

Port 9782

Close the file after saving the changes.

As mentioned the default port is labeled SSH 22:

semanage port -l | grep ssh
ssh_port_t tcp 22

To open SSH port on Firewalld, You should keep the firewall service running and only allow trusted services:

sudo firewall-cmd --add-port=9782/tcp --permanent
sudo firewall-cmd --reload

Use the following command to install the Firewalld and start the service:

sudo yum -y install firewalld
sudo systemctl enable --now firewalld
sudo firewall-cmd --add-port=9782/tcp --permanent
sudo firewall-cmd --reload

You can remove the SSH service with the following command:

sudo firewall-cmd --remove-service=ssh --permanent
sudo firewall-cmd --reload

Run the following command to restart the SSH service and apply the changes:

sudo systemctl restart sshd

Finally verify Listen address for SSH with the following command:

netstat -tunl | grep 9782
tcp 0 0 0.0.0.0:9782 0.0.0.0:* LISTEN
tcp6 0 0 :::9782 :::* LISTEN

Change SSH Port on CentOS Stream 9

First login to the server via SSH console:

ssh root@hostname

Run the following command to install your favorite editor (nano or VIM) on Linux:

dnf install nano -y

Then check the Firewall status with the following command:

systemctl status firewalld

Run the following command to install the Firewalld:

yum install firewalld

Now you need to check again the Firewalld status with the following command:

systemctl status firewalld

Use the following command to enable and start the Firewalld service:

systemctl enable firewalld
systemctl start firewalld

Finally check again the FirewallD status:

systemctl status firewalld

Run the following command to stop the Firewalld:

systemctl stop firewalld

Then restart the Firewalld:

systemctl restart firewalld

Then use the following command to add your custom SSH port number on Firewalld. Fore example, to use port 9782, you can whitelisted with the following command:

sudo firewall-cmd --add-port 9782/tcp
sudo firewall-cmd --add-port 9782/tcp --permanent
sudo firewall-cmd --zone=public --permanent --add-port=9782/tcp

Then run the following command to restart the Firewalld service:

systemctl restart firewalld

Then change SSH port number with the following command:

nano /etc/ssh/sshd_config

Finally run the following command to restart the SSH service:

systemctl restart sshd

Recommended Article: How to Install MailSpring on Centos 7 & 8

Conclusion

As mentioned, hackers can damage your server in the default SSH port mode, so you need to change the default SSH port to increase the security of your server. In this article, we introduced SSH port and you learned how to change SSH port on CentOS 7 , 8 and 9.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

How to Change SSH Port on CentOS 7, 8 and 9 的相关文章

  • scipy 将一个稀疏矩阵的所有行附加到另一个稀疏矩阵

    我有一个 numpy 矩阵 想在其中附加另一个矩阵 这两个矩阵的形状为 m1 shape 2777 5902 m2 shape 695 5902 我想将 m2 附加到 m1 以便新矩阵的形状为 m new shape 3472 5902 当
  • 如何在Python中流式传输和操作大数据文件

    我有一个相对较大 1 GB 的文本文件 我想通过跨类别求和来减小其大小 Geography AgeGroup Gender Race Count County1 1 M 1 12 County1 2 M 1 3 County1 2 M 2
  • 如何在python 3.7中生成条形码

    我正在使用 python 3 7 为了生成条形码 我尝试使用安装 pyBarcode 库pip install pyBarcode 但它显示以下错误 找不到满足 pyBarcode 要求的版本 来自版本 找不到 pyBarcode 的匹配分
  • python 中的并行处理

    在 python 2 7 中进行并行处理的简单代码是什么 我在网上找到的所有示例都很复杂 并且包含不必要的代码 我该如何做一个简单的强力整数分解程序 在每个核心 4 上分解 1 个整数 我真正的程序可能只需要2个核心 并且需要共享信息 我知
  • 用缺失的日期填充其他列 Nan Pandas DataFrame

    我实际上是从几个 Excel 文件中提取数据来监控我的每日卡路里摄入量 我设法使用列表理解来生成日期 我尝试使用合并或连接 但它不起作用 ValueError 您正在尝试合并对象和 float64 列 date list 2021 05 2
  • 如何检查python xlrd库中的excel文件是否有效

    有什么办法与xlrd库来检查您使用的文件是否是有效的 Excel 文件 我知道还有其他库可以检查文件头 我可以使用文件扩展名检查 但为了多平台性我想知道是否有任何我可以使用的功能xlrd库本身在尝试打开文件时可能会返回类似 false 的内
  • Kivy - 有所有颜色名称的列表吗?

    在 Kivy 中 小部件 color属性允许输入其值作为字符串颜色名称 也 例如在 kv file Label color red 是否有所有可能的颜色名称的列表 就在这里 来自Kivy 的文档 https kivy org doc sta
  • 如何在Python中同时运行两只乌龟?

    我试图让两只乌龟一起移动 而不是一只接着另一只移动 例如 a turtle Turtle b turtle Turtle a forward 100 b forward 100 但这只能让他们一前一后地移动 有没有办法让它们同时移动 有没有
  • Mac OS X 中文件系统的 Unicode 编码在 Python 中不正确?

    在 OS X 和 Python 中处理 Unicode 文件名有点困难 我试图在代码中稍后使用文件名作为正则表达式的输入 但文件名中使用的编码似乎与 sys getfilesystemencoding 告诉我的不同 采取以下代码 usr b
  • 在没有模型的情况下将自定义页面添加到 django admin

    我正在尝试在没有模型关联的情况下向管理员添加自定义页面 这就是我迄今为止所取得的成就 class MyCustomAdmin AdminSite def get urls self from django conf urls import
  • 如何使用文本相似性删除 pandas 数据框中相似(不重复)的行?

    我有数千个数据 这些数据可能相似也可能不相似 使用 python 的默认函数 drop duplicates 并没有真正的帮助 因为它们只检测相似的数据 例如 如果我的数据包含类似以下内容怎么办 嗨 早上好 嗨 早上好 Python 不会将
  • Django send_mail SMTPSenderRefused 530 与 gmail

    一段时间以来 我一直在尝试使用 Django 从我正在开发的网站接收电子邮件 现在 我还没有部署它 并且我正在使用Django开发服务器 我不知道这是否会影响它 这是我的 settings py 配置 EMAIL BACKEND djang
  • 在 Windows 上使用 apache mod_wsgi 运行 Flask 应用程序时导入冲突

    我允许您询问我在 Windows 上使用您的 mod wsgi portage 托管 Flask 应用程序时遇到的问题 我有两个烧瓶应用程序 由于导入冲突 只有一个可以同时存在 IE 如果请求申请 1 我有回复 然后 如果我请求应用程序 2
  • 通过索引访问Python字典的元素

    考虑一个像这样的字典 mydict Apple American 16 Mexican 10 Chinese 5 Grapes Arabian 25 Indian 20 例如 我如何访问该字典的特定元素 例如 我想在对 Apple 的第一个
  • 如何在 pandas 中使用 read_fwf 跳过空行?

    I use pandas read fwf http pandas pydata org pandas docs stable generated pandas read fwf htmlPython pandas 0 19 2 中的函数读
  • 使用“默认”环境变量启动新的子进程

    我正在编写一个构建脚本来解析依赖的共享库 及其共享库等 这些共享库在正常情况下是不存在的PATH环境变量 为了使构建过程正常工作 让编译器找到这些库 PATH已更改为包含这些库的目录 构建过程是这样的 加载器脚本 更改 PATH gt 基于
  • Anaconda 无法导入 ssl 但 Python 可以

    Anaconda 3 Jupyter笔记本无法导入ssl 但使用Atom终端导入ssl没有问题 我尝试在 Jupyter 笔记本中导入 ssl 但出现以下错误 C ProgramData Anaconda3 lib ssl py in
  • 动态过滤 pandas 数据框

    我正在尝试使用三列的阈值来过滤 pandas 数据框 import pandas as pd df pd DataFrame A 6 2 10 5 3 B 2 5 3 2 6 C 5 2 1 8 2 df df loc df A gt 0
  • Django 与谷歌图表

    我试图让谷歌图表显示在我的页面上 但我不知道如何将值从 django 视图传递到 javascript 以便我可以绘制图表 姜戈代码 array Year Sales Expenses 2004 1000 400 2005 1170 460
  • 将上下文管理器的动态可迭代链接到单个 with 语句

    我有一堆想要链接的上下文管理器 第一眼看上去 contextlib nested看起来是一个合适的解决方案 但是 此方法在文档中被标记为已弃用 该文档还指出最新的with声明直接允许这样做 自 2 7 版起已弃用 with 语句现在支持此

随机推荐

  • 前端分页插件_免费开源的React前端框架——ReactAdmin

    介绍 ReactAdmin是一个Github上免费开源的前端框架 不是组件库 也不是模板 它是一个框架 采用es6 React和Material Design构建基于Rest GraphQl API的Web应用程序 在React上star数
  • Android实现用户登录和注册界面

    我们在做android项目时经常会用到用户登录 这里呈上实现了Spinner的登录界面 初学的朋友可以直接拿过来使用 本界面使用的是流式布局 也是我最喜欢用的布局方式 同学们可以通过代码了解一下 代码中Intent的使用有点杂乱 主要是为了
  • sql逗号分开的指定列,分成多行

    if object id tempdb dbo tb is not null drop table tb go create table tb id int price varchar 100 customer int cinvcode i
  • 掌握这个技能,再也不用为面试发愁了

    点击上方 前端瓶子君 关注公众号 回复算法 加入前端编程面试算法每日一题群 废话只说一句 码字不易求个 收藏 学会 快行动起来吧 评论区走起 在面试时 经过简单寒暄后 面试官一般先从让候选人自我介绍开始 紧接着就是问候选人简历中所列的项目
  • weblogic CVE-2023-21839 复现

    影响版本 Weblogic 12 2 1 3 0 Weblogic 12 2 1 4 0 Weblogic 14 1 1 0 0 这里是用的docker下载的vulhub的CVE 2023 21839 靶机和攻击机都是192 168 85
  • 2019.08 FSGAN -论文解读

    原文链接 https zhuanlan zhihu com p 138042376 笔者前言 FSGAN Subject Agnostic Face Swapping and Reenactment 是ICCV19的一篇文章 主要工作是面部
  • 高等代数 二次型与矩阵的合同(第6章)1 二次型,标准形,规范形

    一 二次型 6 1 1 概念 2 非退化线性替换 准确地说 应该是将 x x x用 C x Cx Cx带入 这样能保证代换前后二次型中的元不
  • 玩转Mysql系列 - 第15篇:详解视图

    这是Mysql系列第15篇 环境 mysql5 7 25 cmd命令中进行演示 需求背景 电商公司领导说 给我统计一下 当月订单总金额 订单量 男女订单占比等信息 我们啪啦啪啦写了一堆很复杂的sql 然后发给领导 这样一大片sql 发给领导
  • Request对象和response对象

    一 概念 request对象和response对象是通过Servlet容器 如Tomcat 自动创建并传递给Servlet的 Servlet容器负责接收客户端的请求 并将请求信息封装到request对象中 然后将request对象传 递给相
  • C语言实现栈(基于数组)

    栈是一种操作受限的数据结构 只允许从一段操作 而且先进后出 FILO first in last out 这里将栈的操作封装在C语言的头文件里 实现栈的代码如下 include
  • 关于Git看这一篇就够了(IDEA版本)

    目录 一 Git简介 1 1 项目的版本管理 1 2 团队协同开发 1 3 版本管理工具 Git 二 Git下载及安装 2 1 下载Git 2 2 安装Git 2 3 检查 三 Git架构 四 Git基本使用 4 1 创建版本库 4 2 查
  • 132_Springboot总是会自动在/tmp/spring.log生成日志文件问题处理

    原因是项目配置文件中有如下引用
  • 2016年蓝桥杯预赛第十题最大比例

    题目 最大比例 X星球的某个大奖赛设了M级奖励 每个级别的奖金是一个正整数 并且 相邻的两个级别间的比例是个固定值 也就是说 所有级别的奖金数构成了一个等比数列 比如 16 24 36 54 其等比值为 3 2 现在 我们随机调查了一些获奖
  • vue 工程从window 到mac

    ERROR in src assets css theme default scss node modules css loader node modules postcss loader lib node modules sass loa
  • 五十三.L1-003 个位数统计

    include
  • 骨骼蒙皮动画(SkinnedMesh)的原理解析(一)

    一 3D模型动画基本原理和分类 3D模型动画的基本原理是让模型中各顶点的位置随时间变化 主要种类有Morph 变形 动画 关节动画和骨骼蒙皮动画 SkinnedMesh 从动画数据的角度来说 三者一般都采用关键帧技术 即只给出关键帧的数据
  • 使用Flutter之后,我们的CPU占用率降了50%

    近年来 移动互联网迅猛发展 业务需求频繁更新 业务内容动态化需求急剧增加 纯原生开发已经无法满足业务快速增长的需求 因此诞生了多种跨平台开发框架 如 H5 原生开发 React Native 和 Weex 但这两年最受开发者青睐的莫过于 F
  • 自己编写chrome插件

    1 首先你需要一个menifest json文件 manifest version 3 name My Extension version 2 0 action default popup popup html default icon i
  • 【python基础】:分类统计各字符的个数

    功能实现 利用python实现统计一个字符串中数字 字母及其他字符的个数和各个字符的总数 方法一 利用 isdigit isalpha 函数判断字符是否是数字或者字母 代码如下 s input 请输入一串字符 num char space
  • How to Change SSH Port on CentOS 7, 8 and 9

    The default SSH service port value is 22 in which case hackers may be able to launch attacks on the server through port