Join WhatsApp
Join Now
Join Telegram
Join Now

SSH to a Port Other Than 22

Avatar for Noman Mohammad

By Noman Mohammad

Published on:

SSH to a Port Other Than 22
Your rating ?

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)

  1. Check if SSH is installed: Type ssh -V in your terminal. If not installed, use sudo apt install openssh-server (for Ubuntu).
  2. Edit the SSH config file: Open it with sudo nano /etc/ssh/sshd_config.
  3. Find the port line: Change #Port 22 to Port 2222 (or your chosen number).
  4. Save and restart SSH: Press Ctrl+X, then Y, then Enter. Restart with sudo 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! 🌟

Leave a Comment