HiBlog
  • صفحه اصلی
  • خانه وبلاگ
  • دسته بندی ها
    • جذاب ترین ها
      جذاب ترین مطالب
    • های تیوب
      انواع ویدئوهای آموزشی
    • های ‌کست
      انواع پادکست های جذاب
    • های کادمی
      آموزش ها و ترفندهای وب
  • درباره ما
  • ارتباط با ما
FA
EN
RU
Language:
FA
EN
RU
Article Stats
Most Interesting
Category
A. Mounesi
Author
17 April 2025
Release Date
84
Views
FA
EN
RU
Post Languages
How to change SSH port in Linux

How to change SSH port in Linux

Table of Content

Article Stats
  1. Change SSH port
  2. Select a new port number
  3. Firewall settings
  4. SSH Configuration

By default, port 22 is defined for SSH in Linux. Changing the default port can help increase server security and may reduce automated SSH attacks.

In this tutorial, we will explain how to change the SSH port and define it in the Linux firewall.

Change SSH port

To change the default SSH port to a desired port, follow these steps:

Select a new port number

Some ports are reserved by Linux services. So you should be careful not to choose these numbers. We recommend choosing a number higher than 1024.

For example, we want to change the SSH port to 7743.

Firewall settings

Before changing the SSH port, the new port first needs to be allowed or opened in the firewall.

Ubuntu: If you are using the UFW firewall on Ubuntu (the default firewall of the operating system), the following command is used to open port 7743:

sudo ufw allow 7743/tcp

CentOS: In CentOS operating system, firewall management is done by FirewallD by default. You can use the following command to open port 7743 in FirewallD:

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

If you are using iptables as a firewall, you can use the following command to open port 7743:

sudo iptables -A INPUT -p tcp --dport 7743 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT

If SELinux is enabled on the operating system, you can use the following command to add a new port to the SELinux rules:

sudo semanage port -a -t ssh_port_t -p tcp 7743

SSH Configuration

Open the SSH configuration file at /etc/ssh/sshd_config with a text editor:

sudo nano /etc/ssh/sshd_config

Find the line that says Port 22. This line usually has a # symbol at the beginning. Remove the # symbol and change the number 22 to 7743.

Be careful when modifying the SSH configuration file. Incorrect configuration may prevent the SSH service from running.

Then save the file and restart the SSH service using the following command:

sudo systemctl restart ssh

In CentOS, the following command is used to restart SSH:

sudo systemctl restart sshd

The SSH port has now changed and you can connect to the server through the new port.

Share Post
hidata.org/en/blog/change-ssh-port-in-linux/
Copy Link
In Social Media

Add Comment

You’re replying to
captcha

Related Articles

How to Run Python Scripts on Hosting Without Terminal Access

How to Run Python Scripts on Hosting Without Terminal Access

Python programming is one of the most popular areas of web development and bot creation. However, shared hosting users...
2 weeks ago
View Article
How to Install MikroTik on an Ubuntu Server

How to Install MikroTik on an Ubuntu Server

MikroTik is an advanced router operating system that provides a variety of features for network management. The CHR (Cloud...
2 weeks ago
View Article
Comprehensive Guide to Using a Virtual Server / How to Use a VPS?

Comprehensive Guide to Using a Virtual Server / How to Use a VPS?

Today, with the growth of digital services, website design, application development, and the execution of web-based projects, the use...
3 weeks ago
View Article
Web Hosting
  • Professional cPanel Hosting
  • High-Traffic cPanel Hosting
  • File Hosting
Dedicated Server
  • Europe Dedicated Server
About HiData
Hi Data
Good Hosting Experience
Since April 2014, HiData has been hosting thousands of online businesses with strong and premium infrastructure in the best datacenters in Iran and worldwide. We use new-generation servers with powerful processors, high-capacity networks, and strict data security policies to meet your hosting needs at the highest standards. Our support team is available 24/7 through ticket and phone. Speed, stability, and peace of mind are not just promises. They are the identity of HiData.
Virtual Server
  • Germany NVMe VPS
  • Russia NVMe VPS
  • Turkey SSD VPS
  • Germany SATA VPS
  • Storage VPS
  • Cloud VPS
Other Services
  • Domain Services
  • Licensing System
  • Reseller
Phone 1: +98-9009019
HiTube HiCademy HiCast HiBlog
Address
HQ Address: Unit 8, 2nd Floor, Tala Commercial Complex, Imam Khomeini St., Abhar
Contact Phones
+98-9009019
24/7 Support
Support Email: info@hidata.org
© 2025 HiData
All rights reserved for hidata.org
HiData Store
The best prices for the world's leading brands