DEV Community

Cover image for Configuring and Securing SSH Access in Linux
Sana Muhammad Sadiq
Sana Muhammad Sadiq

Posted on

Configuring and Securing SSH Access in Linux

As I continue my RHCSA journey with the 30-day Linux challenge. Today’s topic is all about something that powers remote access and server administration in the Linux world SSH (Secure Shell). If you’ve ever connected to a remote machine securely, you’ve likely used SSH already. But configuring and securing it properly? That’s where many stop short and that’s exactly what we’ll tackle today.

🔍 What is SSH?

SSH (Secure Shell) is a protocol used to securely log into remote systems over a network. It encrypts all the traffic, preventing eavesdropping, connection hijacking and other attacks.

🛠️ Basic SSH Command

ssh username@remote_host
Enter fullscreen mode Exit fullscreen mode
  • username: user on the remote machine
  • remote_host: IP or hostname of the server

📦 Installing SSH

On Ubuntu/Debian:

sudo apt install openssh-server
Enter fullscreen mode Exit fullscreen mode

On RHEL/CentOS:

sudo dnf install openssh-server
Enter fullscreen mode Exit fullscreen mode

🔐 Start & Enable SSH Service

sudo systemctl start sshd
sudo systemctl enable sshd
Enter fullscreen mode Exit fullscreen mode

🔐 Securing SSH Access (Best Practices)

Change the default port
Edit /etc/ssh/sshd_config:

Port 2222
Enter fullscreen mode Exit fullscreen mode

Disable root login

PermitRootLogin no
Enter fullscreen mode Exit fullscreen mode

Use SSH key authentication

ssh-keygen
ssh-copy-id user@remote_host
Enter fullscreen mode Exit fullscreen mode

Limit users who can login

AllowUsers sana ali devops
Enter fullscreen mode Exit fullscreen mode

Use Fail2Ban or firewall rules to block brute-force attempts.

📁 Real-Time Use Cases

🔹 DevOps teams use SSH keys for secure deployments.
🔹 Sysadmins monitor cloud instances without exposing passwords.
🔹 Developers connect to staging servers to test builds securely.

💡 Pro Tips

  • Always backup your ~/.ssh directory.
  • Use ssh -v to troubleshoot SSH issues.
  • Audit /var/log/auth.log for unauthorized attempts.

🧠 Quick Summary

Task Command / Action
Connect to SSH ssh user@ip
Generate SSH key ssh-keygen
Copy key to remote ssh-copy-id user@host
Change default port Edit /etc/ssh/sshd_config
Restart service sudo systemctl restart sshd
Disable root login PermitRootLogin no

SSH is your gateway to the Linux world but with great power comes great responsibility. By taking the time to secure your SSH access, you’re not just connecting remotely; you’re building a safer system.

Image description

I'd love to hear your thoughts, insights or experiences with Linux. Feel free to share and join the conversation [ Connect with me on LinkedIn www.linkedin.com/in/techwithsana ]💜

#30dayslinuxchallenge #redhat #networking #cloudcomputing #cloudengineer #cloudarchitect #cloud #RHCSA #RHCE #RHEL #WomeninTech #Technology

Top comments (0)

OSZAR »