SSH (Secure Shell) lets you control a computer remotely. By default, SSH uses port 22. But hackers know this! Changing the port adds extra security. Think of it like hiding your house key.
Using a different port reduces automated attacks. Bots often target port 22. Switching to a random port (like 2222 or 4567) makes your system harder to find. It’s a small step with big safety benefits.
How to SSH to a Different Port (Step-by-Step)
- Check if SSH is installed: Type
ssh -V
in your terminal. If not installed, usesudo apt install openssh-server
(for Ubuntu). - Edit the SSH config file: Open it with
sudo nano /etc/ssh/sshd_config
. - Find the port line: Change
#Port 22
toPort 2222
(or your chosen number). - Save and restart SSH: Press
Ctrl+X
, thenY
, thenEnter
. Restart withsudo systemctl restart sshd
.
Now, connect using ssh username@ip -p 2222
. Replace “2222” with your port.
Troubleshooting Common Issues
- Connection refused? Check if the new port is open in your firewall. Use
sudo ufw allow 2222
(for Ubuntu). - Forgot to restart SSH? The changes won’t work until you restart the service.
- Port already in use? Pick another number between 1024 and 65535. Avoid common ports like 80 or 443.
For advanced setups, visit the Ubuntu SSH Guide.
Pros and Cons of Changing SSH Ports
Pros
- Fewer hacking attempts.
- Less clutter in server logs.
- Simple to set up.
Cons
- You must remember the new port.
- Some apps might need manual port updates.
Always back up config files before editing. Learn more from the Red Hat Security Guide.
FAQs
1. Can I use port 443 for SSH?
Yes! But avoid conflicts with web traffic.
2. Is changing the SSH port enough for security?
No. Also use SSH keys and disable password logins.
3. How do I check if my new port works?
Run nc -zv your-ip 2222
(install netcat if needed).
Follow these steps to stay safe. For more tips, see the OpenSSH Official Docs. Share this guide to help others! 🌟