api-and-interface-desi…
Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints,…
Audit and harden VPS security — fail2ban, SSH hardening, firewall setup
$ npx -y skills add kevinnft/ai-agent-skills --skill vps-security-hardening --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/vps-security-hardeningContext preview
The summary Claude sees to decide when to auto-load this skill.
Audit and harden VPS security — fail2ban, SSH hardening, firewall setup
name: vps-security-hardening description: Audit and harden VPS security — fail2ban, SSH hardening, firewall setup tags: [security, vps, ssh, fail2ban, linux, ubuntu] origin: unknown source_license: see upstream language: en
Audit and harden VPS security with fail2ban (brute-force protection), SSH hardening, and optional firewall setup.
**Before hardening, ensure you can SSH into the VPS.**
VPS providers often disable password auth by default. You need to add your SSH key first.
1. **Generate SSH key locally** (if not exists):
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N '' -C "user@machine" cat ~/.ssh/id_ed25519.pub
2. **Login to VPS via web console** (provider dashboard → Console/Terminal)
3. **Add public key to VPS**:
mkdir -p ~/.ssh echo "ssh-ed25519 AAAA... user@machine" >> ~/.ssh/authorized_keys chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
4. **Test from local machine**:
ssh root@VPS_IP
Most providers (DigitalOcean, Vultr, Biznet, etc.) have "Add SSH Key" in dashboard:
**Only if web console is unavailable:**
1. Login via web console 2. Edit SSH config:
echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config.d/99-temp-password.conf systemctl reload sshd
3. SSH in with password, add your key 4. Remove temp config:
rm /etc/ssh/sshd_config.d/99-temp-password.conf systemctl reload sshd
**Problem:** `sshpass -p 'password' ssh user@host` fails with "Permission denied (publickey)" even with correct password.
**Why:** VPS has `PasswordAuthentication no` in sshd_config — password auth is disabled at server level.
**Solution:** Use web console to add SSH key first (see Option 1 above).
1. **Check running processes**
ps aux --sort=-%mem | head -20 systemctl list-units --type=service --state=running
2. **Check listening ports**
sudo ss -tulpn sudo netstat -tulpn
3. **Check for rootkits/malware**
# Hidden processes ps aux | wc -l ls /proc | grep -E '^[0-9]+$' | wc -l # Recent failed logins sudo grep "Failed password" /var/log/auth.log | tail -20
4. **Check user accounts**
cat /etc/passwd | grep -E '/bin/(bash|sh)$' sudo lastlog
5. **Resource usage**
free -h df -h uptime
# Install sudo apt-get update sudo apt-get install -y fail2ban # Enable and start sudo systemctl enable fail2ban sudo systemctl start fail2ban
Create `/etc/fail2ban/jail.local`:
[DEFAULT] bantime = 3600 # Ban for 1 hour findtime = 600 # Count failures in last 10 minutes maxretry = 5 # Ban after 5 failures [sshd] enabled = true port = 22 logpath = /var/log/auth.log maxretry = 5
Restart:
sudo systemctl restart fail2ban sudo fail2ban-client status sshd
Create `/etc/ssh/sshd_config.d/99-hardening.conf`:
# Disable root login PermitRootLogin no # Enable public key auth PubkeyAuthentication yes # Disable empty passwords PermitEmptyPasswords no # Limit auth attempts MaxAuthTries 3 # Disable X11 forwarding X11Forwarding no # Disable TCP forwarding AllowTcpForwarding no # Disable agent forwarding AllowAgentForwarding no # Set login grace time LoginGraceTime 30 # Limit sessions MaxSessions 2 # Strong ciphers only Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com # Strong MACs only MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com # Strong key exchange KexAlgorithms curve25519-sha256,diffie-hellman-group-exchange-sha256
Test and reload:
sudo sshd -t sudo systemctl reload sshd
# fail2ban status sudo fail2ban-client status sshd # SSH config sudo sshd -T | grep -E '(permitrootlogin|maxauthtries|x11forwarding)' # Check banned IPs sudo fail2ban-client get sshd banip
**DO NOT automatically disable password authentication!**
# Check if user has SSH keys cat ~/.ssh/authorized_keys # Check how user is currently connected sudo grep "Accepted" /var/log/auth.log | tail -5
**If user logs in with PASSWORD:**
**If user logs in with SSH KEY:**
**CRITICAL:** If user says "keep password" or "tanpa ssh key" or similar:
**User knows their use case better than you:**
**Problem:** User currently uses password, you disable it, user gets locked out.
**Solution:**
191 attribution-first agent skills for Hermes Agent, Claude Code, Cursor — one installer, 28 categories, searchable catalog. See NOTICE for upstream attribution.
Repo: kevinnft/ai-agent-skills
Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints,…
Tests in real browsers. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze…
Automates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test…
Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to…
Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend…
Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure…