Setting up SSH for secure remote access on Rocky Linux is an essential skill for system administrators and developers alike. SSH (Secure Shell) enables encrypted communication between systems, ensuring data confidentiality and integrity during remote management. In this blog, we will cover everything you need to know – from installation to securing your SSH server for enhanced protection.
📹 Watch the Step-by-Step Process in This Video:
What is SSH and Why Is It Important?
SSH, or Secure Shell, is a cryptographic protocol that allows secure communication over an unsecured network. It is widely used for remote server access, file transfers, and executing commands securely.
By setting up SSH on your Rocky Linux system, you can:
- Manage servers remotely.
- Transfer files securely.
- Enhance the overall security of your system.
Step 1: Installing the SSH Server
To begin using SSH, follow these steps to install and enable the SSH server on your Rocky Linux system.
- Update Your System
Ensure your system is up-to-date: - Install the OpenSSH Server Package
Use the following command to install the SSH server: - Check the SSH Service Status
Verify if the SSH service is running:If the service is inactive, proceed to start and enable it.
- Start and Enable the SSH Service
Start the SSH service:Enable it to start automatically at boot:
- Open the SSH Port in the Firewall
Allow SSH traffic through the firewall: - Test the Installation
Verify the SSH server is operational by running a local test:If successful, the SSH server is ready for remote connections.
Step 2: Connecting to the SSH Server
- Find Your Server’s IP Address
Run this command to find the IP address of your server: - Connect Using SSH
Use thessh
command to connect to the server from a client system:Replace
username
with your system’s username and<IP-address>
with your server’s IP address. - Verify the Connection
Once you enter your password, you should be logged into the server.
Step 3: Securing Your SSH Server
For added security, modify the SSH configuration:
- Edit the SSH Configuration File
Open the configuration file: - Change the Default Port
Update the port to a non-standard number (e.g., 2222): - Disable Root Login
Prevent root login to enhance security: - Allow Specific Users
Limit access to specific users: - Apply and Restart
Save the file, validate it, and restart the SSH service: - Update SELinux Settings
If SELinux blocks the new port, allow it using: - Update the Firewall
Open the new port in the firewall:
Step 4: Enable Key-Based Authentication
- Generate an SSH Key Pair
On your client system, generate a key pair: - Copy the Public Key to the Server
Use thessh-copy-id
command to transfer the public key: - Disable Password Authentication
For maximum security, disable password-based login: - Restart SSH
Apply the changes by restarting the SSH service:
Step 5: Troubleshooting Common Issues
- Ensure the Firewall is Configured
Verify the SSH port is open: - Validate Configuration Syntax
Check for syntax errors in the SSH configuration file: - Check SELinux Logs
If issues persist, review SELinux logs for any denials:
FAQs
Q1: How do I find the IP address of my server?
Use the ip addr
command to view the network details.
Q2: Can I use a different port for SSH?
Yes, update the port in /etc/ssh/sshd_config
and restart the SSH service.
Q3: How do I connect to an SSH server from Windows?
Use tools like PuTTY or MobaXterm.
Q4: What if SELinux blocks my SSH port?
Allow the port using semanage
as shown above.
Q5: Is it necessary to disable root login?
Yes, disabling root login significantly reduces security risks.
Conclusion
By following this guide, you have successfully set up SSH on your Rocky Linux system, secured it with best practices, and enabled key-based authentication for enhanced security.
📹 Watch the detailed video tutorial here: How to Set Up SSH for Secure Remote Access on Rocky Linux
Stay tuned for more tutorials, and don’t forget to share your feedback in the comments!