How to Change Your SSH Port for Better Security

By default, SSH runs on port 22, which is commonly targeted by automated attacks. Changing the SSH port is a simple yet effective way to reduce unauthorized login attempts and improve server security.

Step-by-Step Guide:

Step 1: Connect to Your VPS via SSH

Use your SSH client (like PuTTY or Terminal) to log in as the root user.

Step 2: Edit the SSH Configuration File

Open the SSH config file in a text editor:

nano /etc/ssh/sshd_config

Step 3: Find and Change the Port Number

Look for the line that says:

#Port 22

Uncomment it (remove the #) and change 22 to your preferred port number, e.g. 2222:

Port 2222

Step 4: Save and Exit

In nano, press CTRL + X to exit, then Y to save.

Step 5: Update Your Firewall Rules

Make sure the new SSH port is allowed in your firewall. For example, using ufw:

ufw allow 2222/tcp

Step 6: Restart SSH Service

systemctl restart sshd

Step 7: Test the New Port

Open a new SSH session and connect using the new port:

ssh -p 2222 root@your_vps_ip

Tips / Common Issues:

  • ✅ Always keep a second SSH session open while testing the new port, so you can revert if something goes wrong.
  • ✅ Avoid using ports commonly used by other services (like 80, 443, etc.).

FAQs:

Q: What if I lose connection after changing the port?
You can revert to the default port by editing the sshd_config file again via the VPS console or a backup SSH session.

Q: Is changing the port enough to secure SSH?
It’s a good step, but also consider using SSH keys and disabling password authentication for stronger security.

  • ssh port change, secure ssh, change ssh port, vps, ssh hardening, linux, ssh, server security, port 22, firewall configuration
  • 0 Пользователи нашли это полезным
Помог ли вам данный ответ?

Связанные статьи

How to Connect to Your VPS via SSH

SSH (Secure Shell) is a protocol used to securely connect to your VPS. Follow the steps below to...

How to Create a New User with Sudo Access on Your VPS

Creating a new user with sudo access improves the security of your VPS by limiting the use of the...

How to Update and Upgrade Your VPS

Keeping your VPS up to date is essential for security and performance. Here’s how to update and...

How to Check Your VPS Resource Usage

Monitoring your VPS resource usage helps you keep your server performing well. Here’s how you can...

How to Reboot Your VPS Safely

<p>Sometimes, you need to reboot your VPS to apply updates or fix issues. Here’s how to do...