SSH: The Secure Protocol Behind Port 22

Listen to this Post

Featured Image
SSH (Secure Shell) is the protocol that uses port 22 by default. It is a cryptographic network protocol designed for secure remote login, command execution, and data communication over an unsecured network. SSH provides strong encryption, authentication, and integrity checks, making it a fundamental tool for system administrators and cybersecurity professionals.

You Should Know:

1. Basic SSH Command

To connect to a remote server via SSH:

ssh username@remote_host -p 22

Replace `username` with your remote username and `remote_host` with the server’s IP or domain.

2. Key-Based Authentication (More Secure Than Passwords)

Generate an SSH key pair:

ssh-keygen -t rsa -b 4096

Copy the public key to the remote server:

ssh-copy-id username@remote_host
  1. Changing the Default SSH Port (Security Through Obscurity)

Edit the SSH config file:

sudo nano /etc/ssh/sshd_config

Change the line:

Port 22 → Port 2222 

Restart SSH:

sudo systemctl restart sshd

4. Disabling Root Login (Best Practice)

In `/etc/ssh/sshd_config`, set:

PermitRootLogin no 

5. Monitoring SSH Access Attempts

Check failed login attempts:

sudo grep "Failed password" /var/log/auth.log

Or use `journalctl` for systemd-based systems:

journalctl -u sshd --no-pager | grep "Failed"
  1. Using SSH for Secure File Transfer (SFTP/SCP)

Transfer a file via SCP:

scp file.txt username@remote_host:/path/to/destination

Use SFTP for interactive file transfer:

sftp username@remote_host

7. SSH Tunneling (Port Forwarding)

Local port forwarding (access remote service locally):

ssh -L 8080:localhost:80 username@remote_host

Remote port forwarding (expose local service remotely):

ssh -R 9000:localhost:3000 username@remote_host

8. Hardening SSH with Fail2Ban

Install Fail2Ban to block brute-force attacks:

sudo apt install fail2ban  Debian/Ubuntu 
sudo systemctl enable --now fail2ban 

Configure SSH protection in `/etc/fail2ban/jail.local`:

[bash] 
enabled = true 
maxretry = 3 

What Undercode Say:

SSH is a cornerstone of secure remote administration, but misconfigurations can lead to breaches. Always:
– Use key-based authentication.
– Disable root login.
– Regularly update SSH software (sudo apt upgrade openssh-server).
– Monitor logs for intrusion attempts.
– Consider multi-factor authentication (MFA) for critical systems.

For advanced users, explore `sshd_config` options like AllowUsers, MaxAuthTries, and `LoginGraceTime` for tighter security.

Expected Output:

A hardened SSH setup with restricted access, encrypted communications, and active monitoring against unauthorized login attempts.

Prediction:

As cyber threats evolve, SSH will remain a prime target for brute-force attacks. Future trends may include:
– Wider adoption of quantum-resistant encryption in SSH.
– AI-driven anomaly detection for SSH traffic.
– Zero-trust integrations replacing traditional SSH access models.

🔗 Explore More: The Sec Master

References:

Reported By: Arun Kl – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 Telegram