How to Change the Default Port of SSH in Linux?

Securing your Linux server is of paramount importance, and one effective step is to modify the default port used by SSH (Secure Shell) for remote access. Changing the default port adds an extra layer of security by making it less predictable for potential attackers. In this guide, we’ll walk you through the process of changing the default SSH port on a Linux system.

Step 1: Connect to Your Server

Before making any changes, ensure you are logged in to your Linux server with administrative privileges. You can use the ssh command to access your server:

ssh username@server_ip

Replace username with your actual username and server_ip with the IP address of your server.

Step 2: Backup SSH Configuration

It’s always a good practice to create a backup of configuration files before making changes. Create a backup of the SSH configuration file:

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_backup

Step 3: Edit SSH Configuration

Use a text editor to modify the SSH configuration file. We’ll use the nano editor, but you can use any text editor you’re comfortable with:

sudo nano /etc/ssh/sshd_config

Locate the line that specifies the default SSH port. By default, it is:

Port 22

Step 4: Change the Port Number

Change the port number to your desired value. Choose a number that is not commonly used and not reserved for other services. For example, you can use 2222:

Port 2222

Step 5: Save and Exit

After making the change, save the file by pressing Ctrl + O, then press Enter. To exit the editor, press Ctrl + X.

Dracula’s High-Performance Sneaker Bot Servers

Score limited-edition kicks and stay ahead in the game with our high-performance Sneaker Servers. Designed for sneakerheads and resellers, these servers offer blazing-fast speeds and unwavering stability. Never miss a release again with DraculaServers’ Sneaker Servers by your side. Level up your sneaker-copping game now.

Ready to secure the freshest kicks? Discover the power of our Sneaker Servers Here! Don’t let slow servers hold you back—unleash your sneaker-bot’s potential with DraculaServers today.

Check out Sneaker Servers Here!

Step 6: Restart SSH Service

To apply the changes, restart the SSH service:

sudo service ssh restart

Step 7: Adjust Firewall Rules

If you are using a firewall, you’ll need to allow traffic on the new SSH port. For example, using iptables, you can run:

sudo iptables -A INPUT -p tcp --dport 2222 -j ACCEPT

Make sure to replace 2222 with the port you’ve chosen. If you’re using a different firewall management tool, adjust the rule accordingly.

Step 8: Test the New Configuration

Before closing your current SSH session, open a new terminal window and attempt to connect to the server using the new port:

ssh -p 2222 username@server_ip

Replace 2222 with the port you’ve set, username with your username, and server_ip with your server’s IP address. If the connection is successful, you’ve configured the new SSH port correctly.

Step 9: Disable Root Login (Optional)

For added security, consider disabling root login via SSH. Locate the following line in the SSH configuration file:

PermitRootLogin yes

Change yes to no:

PermitRootLogin no

Conclusion

Changing the default SSH port is a valuable security measure to protect your Linux server from unauthorized access. By following these steps, you can modify the default port to enhance your server’s security posture. Always exercise caution while making changes to system configurations, and remember to update your firewall settings to allow traffic on the new port.

 

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
× Dracula Servers

Subscribe to DraculaHosting and get exclusive content and discounts on VPS services.