• Domains
  • Web Hosting
  • WordPress Hosting
  • Reseller Hosting
  • Cloud VPS
  • Dedicated Servers
  • Domains
  • Web Hosting
  • WordPress Hosting
  • Reseller Hosting
  • Cloud VPS
  • Dedicated Servers
home/Knowledge Base/Dedicated Servers/Basic Security/Changing the Default SSH Port (Linux / CentOS)
Popular Search:Dedicated Server, CentOS, Web Hosting

Changing the Default SSH Port (Linux / CentOS)

17 views 1 November 26, 2019 aklwebhost

SSH is one of the most commonly attacked services as it provides easy access to full control of a dedicated server. Changing the default SSH port will help prevent an attacker from launching brute force attacks to the default port.

**Change “someportnumber” to a new port number that is not in use for other services.

1. Login to your server as root

2. Within the command line, execute the command line ‘nano /etc/sysconfig/iptables’ to edit the IPTables configuration file.

Add the following line to the configuration file: ‘-A INPUT -m state –state NEW -m tcp -p tcp –dport someportnumber -j ACCEPT’ directly below line ‘-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT’ in the configuration file.

Save and exit by holding down ‘ctrl’ and ‘x’

3. Within the command line run the command ‘service iptables restart’ to restart the IPTables service

4. Run the command ‘service iptables status’ to see if the new rule has been applied (optional)

5. Edit the SSH configuration file with the command ‘nano /etc/ssh/sshd_config’

Modify the line ‘#port 22’ by removing ‘#’ and replacing ’22’ to your new desired port number we opened on the IPTables configuration.

Save and exit by holding down ‘ctrl’ and ‘x’

6. Within the command line, execute ‘service sshd restart’ to restart the SSH service.

7. If you can still access the command line, type ‘ss -tnlp | grep ssh’ to verify SSH is listening on the new port. (optional)

8. Connect to the server via SSH using the new port you selected.

9. Run the command ‘nano /etc/sysconfig/iptables’ to edit the IPTables configuration file again.

Comment out line ‘-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT’ by adding ‘#’ in the beginning of the line to block all connectivity to port 22.

Save and exit by holding down ‘ctrl’ and ‘x’

10. Execute the command ‘service iptables restart’ to restart the IPTables service

Tags:Changing the Default SSH Port (Linux / CentOS)

Was this helpful?

1 Yes  No
Related Articles
  • Securing SSH on Ubuntu 14.04
  • Setup ConfigServer Security and Firewall (CSF) on CentOS 7
  • Securing SNMP (Linux / Windows)
  • Securing NTP (Linux Only)
  • Enabling and basic configuration of the firewall settings (Linux / Ubuntu)
  • Disabling SSDP (Linux / Windows)
Leave A Comment Cancel reply

Basic Security
  • Changing the Default SSH Port (Linux / CentOS)
  • Securing SSH on Ubuntu 14.04
  • Setup ConfigServer Security and Firewall (CSF) on CentOS 7
  • Securing SNMP (Linux / Windows)
  • Securing NTP (Linux Only)
  • Enabling and basic configuration of the firewall settings (Linux / Ubuntu)
View All 8  
Popular Articles
  • Using StrongSwan for IPSec VPN on CentOS 7
  • Disabling SSDP (Linux / Windows)
  • Can I pay by Western Union?
  • Can a Coupon Code Discount Be Carried Forward While I Upgrade My VPS Account
  • Can I pay multiple due invoices using a single transaction?
KB Categories
  • Billing
  • Cloud Hosting
  • CMS Hosting
  • cPanel/WHM Control Panel Guide
  • Dedicated Servers
    • AMD Opteron 6272
    • Arch
    • Backup Storage
    • Bandwidth
    • Basic Security
    • BSD
    • CentOS
    • Containers
    • CoreOS
    • DDoS Protection
    • Debian
    • Dedicated Server Control Panel
    • Intel Core i5 3550
    • Intel Core i5 4570
    • Intel Core i7 3770
    • Intel Core i7 4770
    • Intel Xeon E3 1230 V3
    • Intel Xeon E3 1245 V2
    • IP Space
    • Linux Guides
    • Minecraft
    • Networking
    • Server Apps
    • Server Troubleshooting
    • Ubuntu
    • Windows Guides
    • Windows Server 2008
    • Windows Server 2012
  • Domain Names
  • Email Support Documentation
    • Setup IMAP or POP
    • User Features – How To
    • Webmail – How To
  • FTP (File Transfer Protocol
    • CuteFTP Guide
    • FileZilla Guide
  • Game Servers
  • MySQL and MariaDB
  • Node.js
  • Plesk Web Hosting Guide
  • VPS Server
  • Web Servers

Changing the Default SSH Port (Linux / Ubuntu / Debian)  

  • Privacy Policy
  • Terms of Use
  • © 2022 AKLWEB HOST LLC, All Rights Reserved.

Popular Search:Dedicated Server, CentOS, Web Hosting