• 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
A A
0
ssh
470
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter
4.8/5 - (101 bình chọn)

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

Tags: linuxSSHchange port sshchange portportCentOSRed Hat
Share188Tweet118
Minh Duy Solutions

Minh Duy Solutions

Bài viết liên quan

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.5k
cac lenh co ban trong linux can biet 4316
Hướng dẫn Linux

Các lệnh cơ bản trong Linux cần biết

11/08/2024
1.5k

Để 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.

domain

Các trạng thái tên miền (Domain Status Code)

28/01/2022
1.6k
l u b n nh p t ng sawpdyd5gyq

Quản trị Office 365: Thêm tài khoản Admin Quản Trị Toàn Cầu trên Office 365

26/09/2021
1.5k

Trending.

cach tao doi quoc gia cho tai khoan google 4082

Cách tạo (đổi quốc gia) cho tài khoản Google

24/01/2024
16.5k
cach tao doi quoc gia cho tai khoan google 4082

Cách xóa hồ sơ thanh toán tài khoản Google

24/01/2024
4.3k
57acc582dde37df0a76107d2fb2448d8

Cách Ngắt Link Ảnh Trong Adobe Illustrator, Đơn Giản, Hiệu Quả

04/10/2022
15k
huong dan cai dat laragon moi truong phat trien website de dang va nhanh chong tren windows 4053 2

Hướng dẫn cài đặt Laragon – Môi trường phát triển website dễ dàng và nhanh chóng trên Windows

07/12/2023
5.4k
cach sua loi co ve nhu ban o quoc gia khac voi nguoi quan ly gia dinh google 4097 3

Cách sửa lỗi Có vẻ như bạn ở quốc gia khác với người quản lý gia đình Google

24/01/2024
2.3k
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

  • aaPanel
  • Góc ICT
  • Thiết Kế Đồ Hoạ
  • SEO
  • Hướng dẫn WHMCS
  • Hướng dẫn Hosting
  • Hướng dẫn WordPress
  • Email Zimbra
  • Hướng dẫn DirectAdmin
  • Hướng dẫn Hosting cPanel
  • 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 © 2021 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

Add New Playlist

×
    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 © 2021 Hướng dẫn Minh Duy Solutions