• Về minhduy.vn
  • Đăng ký Hosting
  • Thiết kế Website
  • Khuyến mãi HOT
Hướng Dẫn Sử Dụng Dịch Vụ - Minh Duy Solutions
  • Trang chủ
  • Hosting
    • Hướng dẫn Hosting cPanel
    • Hướng dẫn Hosting DirectAdmin
  • Tên miền
  • Website
    • Hướng dẫn WordPress
    • Hướng dẫn Webmaster
  • Email Doanh Nghiệp
    • Office 365
    • Google Work Space
    • Email Zimbra
  • VPS – Máy chủ
    • Hướng dẫn Linux
    • Hướng dẫn DirectAdmin
  • Hướng dẫn chung
  • Góc ICT
No Result
View All Result
  • Trang chủ
  • Hosting
    • Hướng dẫn Hosting cPanel
    • Hướng dẫn Hosting DirectAdmin
  • Tên miền
  • Website
    • Hướng dẫn WordPress
    • Hướng dẫn Webmaster
  • Email Doanh Nghiệp
    • Office 365
    • Google Work Space
    • Email Zimbra
  • VPS – Máy chủ
    • Hướng dẫn Linux
    • Hướng dẫn DirectAdmin
  • Hướng dẫn chung
  • Góc ICT
No Result
View All Result
Hướng Dẫn Sử Dụng Dịch Vụ - Minh Duy Solutions
No Result
View All Result
Home Hướng dẫn máy chủ Hướng dẫn Linux

Change the SSH Port in CentOS and Red Hat

Minh Duy Solutions by Minh Duy Solutions
15/07/2024
Reading Time: 4 mins read
158 1
A A
0
ssh
493
SHARES
1.6k
VIEWS
Share on FacebookShare on Twitter

This article explains how to change the default Secure Shell (SSH) port on a CentOS® or Red Hat® Enterprise Linux® server.

 
 

Open and edit the SSH daemon configuration file

  1. Run the following command to open the sshd_config file:

    [root@server-01 ~]# vi /etc/ssh/sshd_config

  2. Use the arrow keys to scroll through the file until you locate the following text:

    #Port 22
    #AddressFamily any
    #ListenAddress 0.0.0.0
    #ListenAddress ::
    
  3. Place the cursor on the line below #Port 22 and press the i key to enter Insert Mode.

  4. Press the Enter key to create a new line and type Port <Specified Port Number>. Port 2021 is the new SSH port in the following example:

    #Port 22
    Port 2021
    #AddressFamily any
    #ListenAddress 0.0.0.0
    #ListenAddress ::
    
  5. Press the Esc key to exit Insert Mode. Next, quit vi by typing :wq and pressing the Enter key.

 
 

Bind SSH daemon to the new port

  1. Install the policycoreutils package to bind the SSH daemon to the new SSH port by using the following command:

    [root@server-01 ~]# yum install policycoreutils

  2. Type y and press the Enter key to continue with the installation. When this task completes, add the following rules
    to ensure that the SSH daemon binds with the specified port:

    [root@server-01 ~]# semanage port -a -t ssh_port_t -p tcp 2021
    [root@server-01 ~]# semanage port -m -t ssh_port_t -p tcp 2021
    
  3. Next restart the SSH daemon:

    [root@server-01 ~]# systemctl restart sshd

 
 

Verify the bind to the new port

Ensure that the port changes took effect by using either the netstat or ss command as shown in the following example:

    [root@server-01 ~]# ss -tlpn| grep ssh
    LISTEN   0         128                 0.0.0.0:2021             0.0.0.0:*        users:(("sshd",pid=28065,fd=4))
    LISTEN   0         128                    [::]:2021                [::]:*        users:(("sshd",pid=28065,fd=6))
    [root@server-01 ~]# netstat -tlpn| grep ssh
    tcp        0      0 0.0.0.0:2021            0.0.0.0:*               LISTEN      28065 sshd
    tcp6       0      0 :::2021                 :::*                    LISTEN      28065 sshd

As you can see, both commands show that Port 2021 is now in place.

 
 

Update your firewall

Update your firewall to ensure that incoming connections are allowed to the newly specified port. Enter the following two lines:

    [root@server-01 ~]# sudo firewall-cmd --add-port=2021/tcp --permanent
    success
    [root@server-01 ~]# sudo firewall-cmd --remove-service=ssh --permanent
    success

Note: The first change includes the <desired port>, which is Port 2021 in the example.

 
 

Verify Change by Login

An attempt to SSH should return the following:

`ssh: connect to host 104.130.26.57 port 22: No route to host`

Now, by using the -p <Port Number> option, you should be able to log in successfully:

    ssh root@104.130.26.57 -p 2021
    root@104.130.26.57's password:

Updated 7 months ago

4.8/5 - (101 bình chọn)
Tags: linuxSSHchange port sshchange portportCentOSRed Hat
Share197Tweet123
Minh Duy Solutions

Minh Duy Solutions

Bài viết liên quan

thiet lap dung luong ram toi da cho redis 4629
Hướng dẫn Linux

Thiết lập dung lượng RAM tối đa cho Redis

11/06/2025
1.5k
huong dan cai dat socks5 tren vps linux 4583
Hướng dẫn máy chủ

Hướng dẫn cài đặt Socks5 trên VPS Linux

26/05/2025
1.5k
mot so lenh co ban kiem tra server khi bi ddos 4461
Hướng dẫn Linux

Một số lệnh cơ bản kiểm tra server khi bị DDoS

13/12/2024
1.5k
4454
Hướng dẫn Linux

Cách kiểm tra máy chủ Linux có bị tấn công DDOS hay không?

13/12/2024
1.5k
mount umount o cung hay thiet bi tren linux 4406
Hướng dẫn Linux

Mount / Umount Ổ Cứng Hay Thiết Bị Trên Linux

30/10/2024
1.5k
20 vi du ve crontab tren he dieu hanh linux 4352
Hướng dẫn Linux

20 ví dụ về crontab trên hệ điều hành Linux

24/09/2024
1.6k

Để lại một bình luận Hủy

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

No Result
View All Result

Recommended.

wordpress bg medblue

Chèn ảnh từ internet vào WordPress

24/09/2021
1.6k
what is cpanel

Vô hiệu hóa spam mail trên cPanel Account

01/02/2023
1.5k

Trending.

outlook là gì

Tạo rules trên Microsoft Outlook

29/05/2026
1.5k
outlook la gi cach cai dat va su dung outlook cho nguoi moi bat dau

Thay đổi thời gian cập nhật gửi nhận Email mới trên Outlook

29/05/2026
1.5k
cach tai toan bo email tren gmail ve may tinh de luu tru 4763

Cách tải toàn bộ email trên Gmail về máy tính để lưu trữ

10/04/2026
1.5k
Tên miền website là gì?

Vòng đời tên miền Việt Nam và Quốc Tế cập nhật năm 2026

07/04/2026
1.5k
binhluan

Cách ẩn comment trên Fanpage để tránh bị cướp khách hàng

09/12/2025
1.5k
Wiki Minh Duy Solutions

WIKI.MINHDUY.VN

Chuyên trang hướng dẫn sử dụng dịch vụ của Minh Duy Solutions

DMCA.com Protection Status

Danh mục

  • GSuite
  • aaPanel
  • Góc ICT
  • Thiết Kế Đồ Hoạ
  • SEO
  • Hướng dẫn WHMCS
  • Hướng dẫn WordPress
  • Email Zimbra
  • Hướng dẫn DirectAdmin
  • Hướng dẫn Hosting cPanel
  • Hướng dẫn Hosting
  • Office 365
  • Hướng dẫn Website
  • Hướng dẫn Linux
  • Hướng dẫn Hosting DirectAdmin
  • Google Work Space
  • Hướng dẫn Webmaster
  • Hướng dẫn máy chủ
  • Hướng dẫn Email Doanh Nghiệp
  • Hướng dẫn Tên miền
  • Hướng dẫn chung
  • Uncategorized

Thẻ

AFC apt-get update apt-get upgrade category chủ thể cPanel debian DirectAdmin email doanh nghiệp Environment Variables giải nén Google Workspace G Suite hosting ioncube khôi phục mật khẩu linux nginx nmap nodejs npm Office 365 OneDrive Outlook out of memory path Paypal phpmyadmin SMTP. GMail SSH sudo swap Symbolic Link tar tar.gz thông báo tên miền tên miền ubuntu user whois WooCommerce WordPress wordpress cơ bản wp rocket Zimbra
  • Về minhduy.vn
  • Đăng ký Hosting
  • Thiết kế Website
  • Khuyến mãi HOT

Copyright © Hướng dẫn Minh Duy Solutions

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
×
    No Result
    View All Result
    • Trang chủ
    • Hosting
      • Hướng dẫn Hosting cPanel
      • Hướng dẫn Hosting DirectAdmin
    • Tên miền
    • Website
      • Hướng dẫn WordPress
      • Hướng dẫn Webmaster
    • Email Doanh Nghiệp
      • Office 365
      • Google Work Space
      • Email Zimbra
    • VPS – Máy chủ
      • Hướng dẫn Linux
      • Hướng dẫn DirectAdmin
    • Hướng dẫn chung
    • Góc ICT

    Copyright © Hướng dẫn Minh Duy Solutions