How To Change SSH Port On Ubuntu VPS Server Stampa

  • secure ssh ubuntu server, linux vps hardening, change ssh port ubuntu vps, custom ssh port setup, ubuntu ssh security, vps ssh protection, secure linux server, ssh configuration guide
  • 29998

How To Change SSH Port On Ubuntu VPS Server

SSH is one of the most targeted services on Linux VPS servers.

By default,
SSH runs on:

 
Port 22
 

Hackers and automated bots constantly scan the internet searching for servers using the default SSH port.

Changing the SSH port helps:

  • reduce automated attacks
  • improve VPS security
  • minimize brute-force attempts
  • harden server infrastructure

In this guide,
you will learn how to safely change the SSH port on an Ubuntu VPS server step-by-step.


Why Change The Default SSH Port?

Changing the default SSH port provides:

  • reduced automated attack attempts
  • improved security
  • lower bot scanning activity
  • additional VPS hardening

Although changing the port alone is not complete security,
it significantly reduces common attack traffic.


Important Warning Before Starting

Before changing SSH port:

  • ensure firewall access is configured
  • keep current SSH session open
  • avoid disconnecting during setup

Incorrect configuration may:

lock you out of your VPS server

Always test the new port before closing your existing session.


Prerequisites

Before starting,
ensure you have:

  • Ubuntu VPS server
  • root or sudo access
  • SSH access enabled

Recommended operating system:

 
Ubuntu 22.04 LTS
 

Step 1 — Connect To VPS Server

Connect using existing SSH connection.

Command:

 
ssh root@your-server-ip
 

Example:

 
ssh root@192.168.1.10
 

Step 2 — Open SSH Configuration File

Open SSH configuration file.

Command:

 
nano /etc/ssh/sshd_config
 

Step 3 — Locate Default SSH Port

Find:

 
#Port 22
 

or:

 
Port 22
 

Step 4 — Change SSH Port

Replace:

 
22
 

with a custom port.

Example:

 
Port 2222
 

You can use:

  • 2222
  • 2200
  • 2022
  • other unused secure ports

Avoid commonly used ports.


Step 5 — Save Configuration File

Save changes and exit editor.

For Nano editor:

  • press CTRL + X
  • press Y
  • press ENTER

Step 6 — Configure Firewall Rules

Allow new SSH port through firewall.

Example:

 
ufw allow 2222/tcp
 

Reload firewall:

 
ufw reload
 

IMPORTANT:
Do NOT remove old SSH port yet.


Step 7 — Restart SSH Service

Restart SSH service.

Command:

 
systemctl restart ssh
 

or:

 
systemctl restart sshd
 

depending on Ubuntu version.


Step 8 — Test New SSH Port

Open a NEW terminal window.

Test connection using new port.

Command:

 
ssh -p 2222 root@your-server-ip
 

Example:

 
ssh -p 2222 root@192.168.1.10
 

If login works successfully,
the new SSH port is configured correctly.


Step 9 — Remove Old SSH Port Rule

After confirming new SSH connection works,
remove old port access.

Command:

 
ufw delete allow 22/tcp
 

Reload firewall:

 
ufw reload
 

Important SSH Security Recommendations

For stronger VPS security:

  • use SSH keys
  • disable root login
  • install Fail2Ban
  • configure firewall
  • use strong passwords
  • enable monitoring

Changing SSH port should be part of layered security.


Important SSH Commands

Restart SSH Service

 
systemctl restart ssh
 

Check SSH Status

 
systemctl status ssh
 

Test SSH Configuration

 
sshd -t
 

Check Open Ports

 
netstat -tulpn
 

Common SSH Port Errors

Connection Refused

Possible causes:

  • firewall blocking port
  • SSH service not restarted
  • incorrect SSH configuration

SSH Service Failed To Restart

Test configuration syntax:

 
sshd -t
 

Fix configuration errors before restarting service.


Port Already In Use

Check active ports:

 
netstat -tulpn
 

Choose another unused port.


Why Businesses Secure SSH Access

Businesses secure SSH because it protects:

  • cloud infrastructure
  • sensitive business data
  • production servers
  • SaaS applications
  • enterprise environments

SSH hardening is critical for infrastructure security.


Why Choose DJ Technologies VPS Hosting

DJ Technologies Linux VPS hosting provides:

  • enterprise virtualization
  • advanced infrastructure security
  • premium low latency network
  • NVMe SSD infrastructure
  • scalable cloud resources
  • optimized VPS environments
  • DDoS protection
  • 24×7 technical support

Our VPS infrastructure is optimized for:

  • secure Linux hosting
  • enterprise workloads
  • business applications
  • SaaS infrastructure
  • scalable cloud deployments

Final Thoughts

Changing the default SSH port is one of the easiest ways to improve Linux VPS security.

By properly configuring:

  • custom SSH ports
  • firewall rules
  • SSH hardening
  • authentication security

you can significantly reduce:

  • automated attacks
  • brute-force attempts
  • unauthorized access risks
  • server vulnerabilities.

Hai trovato utile questa risposta?

« Indietro

Powered by WHMCompleteSolution