DropVPS Team
Writer: John hens
How to Change SSH Port on CentOS 8

Table of Contents
What you will read?
By default, SSH runs on port 22. Changing it helps avoid automated scans and basic attacks.
Step 1: Pick a New SSH Port
Select a custom port between 1024 and 65535 that’s not already in use. We’ll use `2222` as an example:
NEW PORT=2222
You’ll need this value in the next steps.
Step 2: Open the New Port in Firewall
Before changing SSH config, allow the new port through the firewall to avoid locking yourself out:
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload
This ensures future connections will work on the new port.
Step 3: Edit SSH Config File
Update the SSH settings so it listens on the new port instead of 22:
sudo nano /etc/ssh/sshd_config
Find the line #Port 22, uncomment it, and change it:
Port 2222
Save and close the file when done.
Step 4: Restart SSH Service
To apply the config changes, restart the SSH service:
sudo systemctl restart sshd
sudo systemctl status sshd
Confirm there are no errors and the service is active.
Step 5: Test SSH on the New Port
Before logging out, open a second terminal and try connecting with the new port:
ssh -p 2222 youruser@your_server_ip
If successful, you’re good to go.