Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

The Academy 

Harden SSH & Secure Remote Access (Linux)

Harden SSH & Secure Remote Access (Linux)



Introduction:
This practical, legal tutorial shows how to harden SSH on Linux servers: key-based auth, fail2ban, firewalls, user restrictions and basic 2FA. Test everything in your own lab VMs.

Prerequisites:
  • A Linux server/VM (Ubuntu/Debian/CentOS)

  • A separate client machine to SSH from

  • Basic shell knowledge



Steps (do this in your lab):
  1. Create recovery admin user — make sure you have local/console access before locking SSH.


  2. Generate an SSH key on client and copy it to server
    Code
    # on client
    ssh-keygen -t ed25519 -C "[email protected]"
    ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server


  3. Edit SSH server config — open /etc/ssh/sshd_config and set:
    Code
    PermitRootLogin no
    PasswordAuthentication no
    PubkeyAuthentication yes
    AllowUsers youruser
    ChallengeResponseAuthentication no
    UsePAM yes
    Reload SSH:
    Code
    sudo systemctl reload sshd


  4. Install and configure fail2ban to block brute-force:
    Code
    sudo apt update && sudo apt install -y fail2ban
    # minimal /etc/fail2ban/jail.d/local.conf
    [sshd]
    enabled = true
    maxretry = 5
    bantime = 3600


  5. Limit source IPs with firewall (optional)
    Code
    sudo ufw allow from 203.0.113.0/24 to any port 22 proto tcp
    sudo ufw enable


  6. Optional: Add 2FA for SSH (Google Authenticator PAM) — test thoroughly in lab before deploying.



Lab exercises:
  • Attempt a wrong password 6 times from attacker VM and verify fail2ban blocks it.

  • Verify only key-based login works and password login is rejected.



Notes: Always keep a recovery console and do not lock yourself out. Do this only on machines you own or are permitted to manage.

Hit me up for ssh/rdp access pm


Possibly Related Threads...
Thread / Author Replies Views Last Post
by Oh_WellAug 20, 2025 11:00 AM 0 279 Aug 20, 2025 11:00 AM
Last Post: Oh_Well
by Proxies.tvNov 7, 2020 08:49 AM 0 88 Nov 7, 2020 08:49 AM
Last Post: Proxies.tv
by bexpr9Oct 2, 2019 05:00 AM 3 379 Oct 2, 2019 05:00 AM
Last Post: Last_viking