Ever left your front door unlocked by accident? 😅 Imagine doing the same with your server. Leaving an open port is like inviting trouble straight into your digital home. It’s not just a minor oopsie—it’s a full-blown security risk.
Cybercriminals are always on the prowl, looking for weak spots to exploit. Brute force attacks, data breaches, and unauthorized access are just a few of the nightmares you could face. And trust us, no one wants to deal with that kind of mess.
But don’t worry, we’ve got your back. By the end of this guide, you’ll be a security ninja, ready to lock down your connection like a pro. Think of it as adding extra cheese to your pizza—it just makes everything better.
Key Takeaways
- Open ports are like unlocked doors—easy targets for hackers.
- Brute force attacks and data breaches are real risks.
- Securing your server is essential for protecting sensitive data.
- This guide will help you lock down your connection effectively.
- Think of security as an upgrade—it makes everything better.
Understanding the Risks of Exposed SSH Ports
Port 22 is like a neon sign for cybercriminals. 🚨 It’s the default entry point for ssh connections, making it a prime target for hackers. Why? Because it’s predictable, and predictability is a hacker’s best friend.

Why SSH Ports Are Targeted
Automated bots are constantly scanning for open ports, especially port 22. These bots are like digital vultures, looking for weak spots to exploit. A recent example showed 7 attack attempts in just 2 minutes from the same IP address. That’s relentless!
Default configurations make servers low-hanging fruit. Hackers know that many admins don’t change the default settings, leaving the door wide open for brute force attacks. It’s like leaving your keys in the ignition—someone’s bound to take advantage.
Common Vulnerabilities
One of the biggest mistakes? Leaving password authentication enabled. Weak passwords are an open invitation for unauthorized access. Another issue is failing to monitor logs. Attackers often leave traces, like repeated SYN packets, which can indicate a brute force attempt.
Imagine the 3am nightmare scenario: an attacker gets through. They could install malware, steal sensitive data, or even shut down your ssh server. The fallout? A mess you don’t want to deal with. For more insights on securing your setup, check out this guide on SSH vulnerabilities.
How to Identify an Exposed SSH Port
Ever wondered if your server is shouting “come on in” to hackers? 🚨 Identifying open ports is like playing digital detective—it’s all about spotting the clues before trouble arrives. Let’s dive into the tools and commands that’ll help you uncover any vulnerabilities.

Using Network Scanning Tools
First up, nmap. This powerful tool scans your network for open ports and services. Run a quick scan with the command nmap -sV your-server-ip. If you see port 22 listed, it’s time to take action. Pro tip: If the scan shows other unnecessary ports open, close them ASAP.
Another handy tool is ss. Use ss -tuln to list all listening ports. Look for port 22 in the output—if it’s there, your server might be exposed. For a deeper dive, check out this guide on check TCP port usage.
Checking SSH Configuration
Next, inspect your ssh configuration file. Open it with sudo nano /etc/ssh/sshd_config. If you spot Port 22 in the file, sound the alarms! Change it to a non-default port to reduce risk.
Here’s a quick checklist to spot red flags:
- Port 22 is listed in your config file.
- Unnecessary ports are open and listening.
- The SSH service is running on the default port.
By following these steps, you’ll know exactly where your server stands. Stay vigilant, and keep those doors locked! 🔒
Changing the Default SSH Port
Default settings are a hacker’s best friend—time to break up that relationship. 🚫 Sticking with port 22 is like rolling out the welcome mat for cybercriminals. Let’s upgrade your server’s security by changing the default port.

Selecting a New Port Number
Picking a new port number is like choosing a secret hideout—make it hard to guess. Avoid common ports like 80 or 443, as they’re often targeted. Instead, opt for numbers between 49152 and 65535. These are less likely to clash with other services.
Pro tip: Pick a number you’ll remember, like your birth year plus 50,000. Just make sure it’s not something obvious, like 12345. 🎯
Editing the SSH Configuration File
Now, let’s tweak the configuration file. Open it with sudo nano /etc/ssh/sshd_config. Look for the line that says Port 22 and replace it with your new port number. Save the file and exit.
Before you celebrate, double-check your work. A typo could lock you out of your own ssh service. Here’s a quick safety checklist:
- Ensure the new port is open in your firewall.
- Test the connection before closing the current session.
- Keep a backup of the original config file—just in case.
By following these steps, you’ll make your server a fortress. Hackers won’t know what hit them! 🔒
Adjusting Firewall Settings
Think of your firewall as the bouncer at a club—only the right guests get in. 🚪 Once you’ve changed your ssh port, it’s time to update your firewall settings. This ensures only authorized traffic can access your server via the new port.

Allowing Traffic on the New Port
First, open the new port in your firewall. If you’re using UFW, the command is simple: sudo ufw allow [new-port-number]. This tells the firewall to let traffic through the new door. 🚀
Pro tip: Always test your rules with a burner device. Be your own hacker and ensure everything works as expected. 🔍
Using UFW for Firewall Management
UFW (Uncomplicated Firewall) is your best friend for managing firewall settings. Start by checking the status with sudo ufw status. This shows which ports are open and where the traffic is flowing.
For Hostinger users, hPanel makes it even easier. Navigate to the firewall section and add your new port. It’s like building your digital fortress wall 🏰—strong and secure.
Remember the 5-second rule: Never apply firewall changes without testing. A small mistake could lock you out of your vps. Stay safe, stay smart! 🔒
Restarting the SSH Service
Ever felt like your server needs a quick refresh? 🔄 Restarting the ssh service is the IT equivalent of turning it off and on again. It’s simple, effective, and often solves lingering issues. Plus, it’s not a breakup—your server will thank you later.

Using Systemctl to Restart SSH
To restart the ssh service, use the sudo systemctl command. Here’s how:
sudo systemctl restart ssh
This command tells your server to stop and start the service. It’s quick, painless, and ensures everything runs smoothly. Pro tip: Always keep two SSH sessions open during this process. If something goes wrong, you’ll still have access.
Verifying the Service Status
After restarting, verify the status with:
sudo systemctl status ssh
Look for the word “active” in the output. If you see “failed” or “inactive,” don’t panic. Check the logs for errors and try restarting again. Here’s a quick guide to interpreting the status messages:
- Active (running): Everything’s good to go. 🎉
- Active (exited): The service started but stopped. Investigate further.
- Failed: Something went wrong. Check the logs for details.
| Distro | Systemctl Command | Service Command |
|---|---|---|
| Ubuntu | sudo systemctl restart ssh | sudo service ssh restart |
| CentOS | sudo systemctl restart sshd | sudo service sshd restart |
| Debian | sudo systemctl restart ssh | sudo service ssh restart |
By following these steps, you’ll keep your ssh service running like a well-oiled machine. Stay sharp, and happy restarting! 🔧
Testing the New SSH Port
Time to put your new setup to the test—let’s see if it’s hacker-proof! 🕵️♂️ After all the changes, it’s crucial to ensure everything works as planned. No one wants to celebrate prematurely only to find out the door’s still wide open.

Connecting via SSH with the New Port
First, let’s connect server using the new port. Open your terminal and use the following ssh command:
ssh username@your-server-ip -p [new-port-number]
If the connection works, you’re golden! 🎉 If not, don’t panic. Double-check the port number and firewall settings. Pro tip: Keep a backup session open just in case things go sideways.
Using ss and netstat Commands
Next, let’s verify the port is active. Use the ss or netstat commands to check:
ss -tuln | grep [new-port-number]
Or:
netstat -tuln | grep [new-port-number]
If you see the new port listed, it’s working! 🚀 If not, revisit your configuration file and firewall rules. Here’s a quick troubleshooting checklist:
- Ensure the new port is open in the firewall.
- Check for typos in the SSH config file.
- Restart the SSH service if needed.
Pro tip: Celebrate with a small dance if it works! 💃 And if it doesn’t, don’t worry—we’ve got your back with an emergency recovery plan.
Enhancing SSH Security with Key-Based Authentication
Passwords are like old flip phones—time for an upgrade. 🔑 While they’ve served us well, relying solely on them for ssh connections is like using a wooden lock on a bank vault. It’s time to level up your server’s security with key-based authentication. Trust us, it’s the upgrade your digital life deserves.

Key-based authentication replaces passwords with a pair of cryptographic keys. Think of it as a VIP pass for your server—only those with the right key get in. No more guessing games for hackers. 🚫
Generating SSH Keys
Ready to get fancy? Let’s generate your ssh keys. Open your terminal and type:
ssh-keygen -t rsa -b 4096
This command creates a pair of keys: a private one (your secret) and a public one (the VIP pass). Store your private key safely—like you would with cat videos. 🐱 Pro tip: Add a passphrase for an extra layer of security.
Here’s a quick comparison of key generation methods across operating systems:
| OS | Command | Key Location |
|---|---|---|
| Linux | ssh-keygen -t rsa | ~/.ssh/id_rsa |
| macOS | ssh-keygen -t ed25519 | ~/.ssh/id_ed25519 |
| Windows | ssh-keygen -t rsa -b 4096 | C:\Users\YourUser\.ssh\id_rsa |
Disabling Password Authentication
Now that you’ve got your keys, it’s time to lock the door on passwords. Open your ssh configuration file with:
sudo nano /etc/ssh/sshd_config
Find the line that says PasswordAuthentication yes and change it to no. Save the file and restart the SSH service. 🚀
Here’s why this matters: Password-only servers are like horror stories waiting to happen. Brute force attacks, data breaches, and sleepless nights—none of it’s worth the risk. Upgrade to key-based authentication and sleep like a baby. 😴
Pro tip: Backup your keys like cat videos—irreplaceable! 🐾 And if you’re feeling extra fancy, add 2FA for the ultimate security flex. 🔒
Implementing Fail2Ban for Brute Force Protection
Imagine your server as a nightclub—Fail2Ban is the bouncer keeping the troublemakers out. 🕶️ This powerful tool blocks repeated failed login attempts, making brute force attacks a thing of the past. It’s like having a digital bodyguard for your server management.

Installing and Configuring Fail2Ban
First, let’s get Fail2Ban up and running. Install it with:
sudo apt install fail2ban -y
Next, copy the default configuration file:
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
Now, tweak the settings in jail.local to protect your ssh connections. Here’s a quick guide:
- Set
enabled = truefor SSH. - Specify the port (e.g.,
port = 22000). - Set
maxretry = 5to ban after 5 failed attempts. - Adjust
bantime = 600to ban for 10 minutes.
Restart Fail2Ban to apply the changes:
sudo systemctl restart fail2ban
Monitoring Fail2Ban Logs
Keep an eye on Fail2Ban’s activity by checking the logs. Use this command to see the status:
sudo fail2ban-client status sshd
Here’s what to look for:
| Log Entry | Meaning |
|---|---|
| Banned IP | An IP was blocked for suspicious activity. |
| Failed Attempts | Number of failed login tries before banning. |
| Ban Duration | How long the IP is banned. |
Pro tip: Customize ban messages to make hackers cry. 😭 For more advanced firewall tips, check out this guide on blocking brute force attacks.
With Fail2Ban, your server is a fortress. Hackers won’t stand a chance! 🔒
Regularly Updating Your Server
Your server is like a plant—ignore it, and it’ll wither away. 🌱 Regular updates are the digital vitamins that keep your server healthy and secure. Without them, you’re just asking for trouble. Think of it as skipping your morning coffee—nothing good comes from it. ☕

Applying Security Patches
Security patches are like band-aids for your server. They fix vulnerabilities before hackers can exploit them. To apply them, use the command:
sudo apt-get update && sudo apt-get upgrade
This ensures your server gets the latest fixes. Pro tip: Schedule these updates during off-peak hours to avoid disruptions. 🕒
Automating Updates
Why manually update when you can automate it? Install unattended-upgrades with:
sudo apt-get install unattended-upgrades
Then, configure it to run automatically. It’s like setting a reminder for your server’s health check. 🩺
Here’s why automation matters:
- Consistency is key—updates happen on time, every time.
- Reduces human error—no more forgetting to update.
- Keeps your vps secure without constant attention.
Pro tip: Treat your server like a Tamagotchi—neglect it, and it dies. 🐣 Stay on top of updates, and your ssh connections will thank you. 🔒
Monitoring SSH Access Logs
Think of your server logs as a detective’s notebook—every clue matters. 🔍 They’re your first line of defense against suspicious activity. By keeping an eye on these logs, you can spot trouble before it spirals out of control.
Whether it’s failed login attempts or unusual traffic, your logs tell the story. The trick? Knowing how to read them like a pro. Let’s dive into the world of log analysis and alerts.
Analyzing Log Files
Start by checking /var/log/auth.log. This file is your go-to for ssh activity. Look for patterns like repeated failed logins or unfamiliar IP addresses. These are red flags that scream “hacker alert!” 🚨
Here’s a quick guide to reading your logs:
- Failed logins: Indicate brute force attempts.
- Successful logins: Verify they’re from trusted sources.
- Unusual timestamps: Late-night logins? Suspicious.
Pro tip: Make log reading your morning coffee ritual. ☕ It’s the best way to stay ahead of threats.
Setting Up Alerts
Don’t wait for trouble to find you—set up alerts instead. Tools like logwatch and fail2ban can notify you of suspicious activity in real-time. Think of them as your digital watchdogs. 🐕
Here’s how to get started:
- Install
logwatchand configure it to email daily summaries. - Set
fail2banto trigger alerts after multiple failed attempts. - Create thresholds for “oh no” moments—like 10 failed logins in 5 minutes.
Pro tip: Customize your alerts to match your server’s traffic patterns. This way, you’ll catch the bad guys without drowning in notifications. 🔒
Conclusion
You’ve just leveled up your server’s defense game—nice work! 🛡️ By securing your ssh connection and changing the default port, you’ve made your setup hacker-resistant. But remember, security is an ongoing process, not a one-time fix.
Don’t let complacency creep in. Regularly monitor your server, update configurations, and stay vigilant. Share this guide with that one friend who’s still using port 22—they’ll thank you later. 😉
Ready to take the next step? Download our security audit checklist and keep your connection rock-solid. Your server is now hacker-proof… until next week’s vulnerabilities! 🚀