Skip to main content
Blog

A Practical Guide to Managing Linux Server SSH Port Configurations

Learn how to change and manage SSH port configurations on Linux business servers to improve security and prevent unauthorized access.

System administrator configuring Linux server settings in a modern office | NetBit Software House and Technology | netbit.pk

Understanding Linux Server SSH Port Management

Managing a business server requires strict security measures to protect sensitive data and applications. By default, Secure Shell (SSH) connections run on port 22. Because this port is universally known, automated bots and malicious actors constantly scan public IP addresses targeting it. Hardening your server infrastructure is a fundamental step that every growing business in Pakistan needs to take. At netbit, our technical teams regularly help local companies secure their digital infrastructure through proper configuration management.

Changing your default SSH port is a simple yet effective way to reduce unwanted log entries and brute-force attack attempts on your server. This guide covers the practical steps required to update your SSH port safely without locking yourself out.

Prerequisites Before You Begin

Before modifying core server configuration files, ensure you have the following in place:

  • Root or sudo-level administrative access to your Linux server (Ubuntu, CentOS, or Debian).
  • An active console or secondary terminal session open to revert changes if something goes wrong.
  • A configured system firewall (like UFW) to allow traffic on your new custom port.

Step-by-Step Guide to Changing the SSH Port

Follow these practical steps to modify your Linux server SSH configuration safely:

1. Edit the SSH Configuration File

Open the main SSH daemon configuration file using a terminal text editor with administrative privileges:

sudo nano /etc/ssh/sshd_config

Scroll through the file to locate the line that specifies the port. By default, it usually appears commented out as:

#Port 22

2. Choose a New Port Number

Uncomment the line by removing the hash symbol (#) and replacing 22 with a high, unreserved port number (typically between 1024 and 65535, avoiding well-known service ports). For example:

Port 49152

3. Update Your Firewall Rules

If you are running a firewall such as UFW, you must explicitly allow incoming connections on your new port before restarting the SSH service. Run the following command:

sudo ufw allow 49152/tcp

Verify your firewall rules to ensure the new port is active and permitted.

4. Restart the SSH Service

Apply the configuration changes by restarting the SSH daemon:

sudo systemctl restart ssh or sudo systemctl restart sshd

5. Test the Connection in a New Terminal

Crucial Step: Do not close your current terminal window. Open a brand-new terminal session on your local machine and attempt to log in using your new port:

ssh username@your_server_ip -p 49152

Once you verify that you can successfully connect using the new port, you can safely close your original administrative session.

Frequently Asked Questions

Why should I change the default SSH port?

Changing the port stops automated script bots from flooding your system logs with failed login attempts, keeping your server resources optimized and secure.

What happens if I get locked out of my server?

If you lose access due to a firewall misconfiguration, you will need to access your server via the hosting provider's web console (VNC or rescue mode) to fix the configuration file.

Partner with NetBit for Robust Server Solutions

Proper server maintenance and security configuration form the backbone of reliable digital operations. Whether you are scaling up your local infrastructure, deploying custom web applications, or upgrading your office networking hardware, netbit tech provides expert engineering solutions tailored to your business goals. Based in Khuzdar, Balochistan, netbit software house delivers comprehensive IT maintenance, networking, custom software development, and CCTV installation services. Contact netbit khuzdar today to secure your IT infrastructure and keep your business running smoothly without interruption.

Discussion

Reader comments.

Share your question, suggestion or experience related to this article.

0 Approved Comments

No comments yet

There are no approved comments on this article yet. You can be the first person to leave one.

Keep Reading

Related insights.

View all articles
WhatsApp