Skip to content
TheChatArchiveThe Chat Archive
Metallama-4-maverick-03-26-experimental· MetaHugging Face LMArena Human Preference 140K

Role You are a IT specialist which is best at pentests and internet security on ssh.…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmistral-medium-2505’s answer.
  1. User

    Role

    You are a IT specialist which is best at pentests and internet security on ssh.

    Task

    Secure ubuntu 22.04 server which communicates on public ip via ssh.

    Context

    This server is responsible for keeping company's backup. Its crucial that only stuff member have access.

  2. Meta Assistant

    A very important task! Securing an SSH server that's exposed to the public internet and holds critical company backups requires utmost care. I'll guide you through a step-by-step hardening process for your Ubuntu 22.04 server. Buckle up!

    Before we start:

    1. Backup your current SSH config: sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup
    2. Ensure you have physical access or an out-of-band management (OOM) (e.g., IPMI, KVM-over-IP) in case something goes wrong, and you get locked out.
    3. Schedule a maintenance window to apply these changes, as some steps will restart the SSH service, causing a brief disconnect.

    Phase 1: Initial Assessment & Updates (10 minutes)

    1. Update & Upgrade: Ensure your system is up-to-date: sudo apt update && sudo apt full-upgrade -y
    2. Install Fail2Ban (intrusion prevention): sudo apt install fail2ban -y
    3. Reboot (optional but recommended): sudo reboot

    Phase 2: SSH Hardening (30 minutes)

    1. Change the default SSH port (reduce botnet scans):
      • Edit /etc/ssh/sshd_config: sudo nano /etc/ssh/sshd_config
      • Change Port 22 to a custom port, e.g., Port 22999 (document this change!)
      • Save and exit (Ctrl+X, Y, Enter)
    2. Disable SSH protocol 1 (deprecated and insecure):
      • In the same /etc/ssh/sshd_config file, add (or uncomment): Protocol 2
    3. Restrict SSH to specific users (company staff):
      • Create a group for SSH access: sudo groupadd sshaccess
      • Add staff members to this group: sudo usermod -aG sshaccess <username> (repeat for each staff member)
      • In /etc/ssh/sshd_config, add: AllowGroups sshaccess
    4. Disable root login (use sudo instead):
      • In /etc/ssh/sshd_config, change: PermitRootLogin no
    5. Use SSH key-based authentication (more secure than passwords):
      • On your staff members' workstations: generate SSH keys if they don't already have them: ssh-keygen -t ed25519 (or rsa -b 4096 for older systems)
      • Copy their public keys (id_ed25519.pub or id_rsa.pub) to the server: ssh-copy-id -i ~/.ssh/id_ed25519.pub -p 22999 user@server_ip (adjust port and user)
      • On the server, in /etc/ssh/sshd_config, set: PubkeyAuthentication yes and PasswordAuthentication no (disables password auth)
    6. Limit SSH authentication attempts:
      • In /etc/ssh/sshd_config, add: MaxAuthTries 3
    7. Set a strong SSH banner ( warning for unauthorized access):
      • Create a file: sudo nano /etc/ssh/banner
      • Paste a stern message, e.g.: "Unauthorized access prohibited. Logins monitored."
      • In /etc/ssh/sshd_config, add: Banner /etc/ssh/banner

    Phase 3: Firewall & Fail2Ban Configuration (15 minutes)

    1. Configure UFW (Uncomplicated Firewall):
      • Install: sudo apt install ufw -y
      • Allow your custom SSH port: sudo ufw allow 22999/tcp (adjust the port)
      • Deny all other incoming traffic by default: sudo ufw default deny incoming
      • Enable UFW: sudo ufw enable
    2. Configure Fail2Ban for SSH:
      • Create a new jail: sudo nano /etc/fail2ban/jail.d/ssh.local
      • Paste:
    [ssh]
    enabled = true
    port = 22999  # Your custom SSH port
    filter = sshd
    logpath = /var/log/auth.log
    maxretry = 3  # 3 attempts, then ban
    bantime = 1h  # Ban for 1 hour
    
    * Restart Fail2Ban: `sudo systemctl restart fail2ban`
    

    Phase 4: System & Kernel Hardening (15 minutes)

    1. Enable TCP Syn Cookies (protect against SYN flood attacks):
      • sudo nano /etc/sysctl.conf
      • Add: net.ipv4.tcp_syncookies = 1
      • Apply: sudo sysctl -p /etc/sysctl.conf
    2. Disable IPv6 (if not needed, reduces attack surface):
      • sudo nano /etc/sysctl.conf
      • Add:
    net.ipv6.conf.all.disable_ipv6 = 1
    net.ipv6.conf.default.disable_ipv6 = 1
    net.ipv6.conf.lo.disable_ipv6 = 1
    
    * Apply: `sudo sysctl -p /etc/sysctl.conf`
    

    3. Harden kernel params: * sudo nano /etc/sysctl.conf * Add:

    kernel.sysrq = 0  # Disable SysRq
    net.ipv4.icmp_echo_ignore_broadcasts = 1  # Ignore ICMP broadcasts
    net.ipv4.icmp_ignore_bogus_error_responses = 1  # Ignore bogus errors
    
    * Apply: `sudo sysctl -p /etc/sysctl.conf`
    

    Phase 5: Finalize & Verify (10 minutes)

    1. Restart SSH service: sudo systemctl restart sshd
    2. Verify SSH is listening on the new port: sudo ss -tlnp | grep sshd
    3. Test your SSH connection from a staff member's workstation: ssh -p 22999 user@server_ip
    4. Double-check Fail2Ban: sudo fail2ban-client status ssh
    5. Monitor logs for any issues: sudo tail -f /var/log/auth.log and sudo journalctl -u sshd

    Additional Recommendations:

    • Set up email notifications for Fail2Ban bans: sudo apt install sendmail and configure /etc/fail2ban/action.d/sendmail.conf
    • Implement Two-Factor Authentication (2FA) for SSH using Google Authenticator or YubiKey (advanced setup)
    • Schedule regular security audits (e.g., OpenVAS, Lynis) and penetration tests (yes, hire me 😉)
    • Consider setting up a hidden SSH port via knockd (port knocking) for extra obscurity

    Document everything! Share these changes with your team, and make sure they understand:

    • The new SSH port
    • SSH key management (backup their keys!)
    • Group membership (sshaccess)
    • 2FA procedures (if implemented)

    Congratulations! Your Ubuntu 22.04 backup server is now seriously hardened against unauthorized access. Keep monitoring, updating, and stay vigilant!

    If you encounter issues or need further assistance, feel free to ask. Now, go backup those company assets with peace of mind!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.