Menu
User

DropVPS Team

Writer: John hens

How to Change SSH Port on Debian 12

How to Change SSH Port on Debian 12

Publication Date

08/10/2025

Category

Articles

Reading Time

2 Min

Table of Contents

Changing the default SSH port from 22 to a custom one is a simple security measure that helps reduce unwanted login attempts.

Step 1: Pick a New Port

Choose an unused TCP port above 1024 to avoid conflicts with system services. For this example, we’ll use port `2222`.

NEW PORT=2222

You can replace 2222 with your desired port number.

Step 2: Allow the New Port in Firewall

Before changing SSH settings, make sure the firewall allows connections on the new port. Otherwise, you might lock yourself out of your server:

sudo ufw allow ${NEW_PORT}/tcp
sudo ufw reload

This ensures uninterrupted access after the change.

Step 3: Update SSH Configuration

Now update the SSH configuration file so the server listens on your new custom port instead of the default:

sudo nano /etc/ssh/sshd_config

Look for the line starting with Port and change it:

Port 2222

Save and close the file.

Step 4: Restart SSH Service

After modifying the configuration file, restart the SSH daemon to apply the new port setting:

sudo systemctl restart ssh

Then verify SSH is running on the new port:

sudo ss -tuln | grep 2222

This confirms the service is active and listening correctly.

Step 5: Test the New SSH Connection

Before ending your current session, test the new port in another terminal to make sure it works as expected:

ssh -p 2222 your_user@your_server_ip

If the connection succeeds, you’re good to go.

Linux VPS
U
Loading...

Related Posts