vps-security-hardening
Skill13 starsChanged 7 months agoMITView on GitHub
Audit and harden VPS security — fail2ban, SSH hardening, firewall setup
- Reads credentials
- Installs packages
1 other project uses a version of this.
Adopted by
Most recently taken up by
- wlzh/skillstheir own version, first seen Aug 28, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- wlzh/skills★ 617same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository143 other files it gives its agents.
- api-and-interface-designSkill
- browser-testing-with-devtoolsSkill
- ci-cd-and-automationSkill
- code-review-and-qualitySkill
- code-simplificationSkill
- context-engineeringSkill
- debugging-and-error-recoverySkill
- deprecation-and-migrationSkill
- documentation-and-adrsSkill
- doubt-driven-developmentSkill
- frontend-ui-engineeringSkill
- git-workflow-and-versioningSkill
- idea-refineSkill
- incremental-implementationSkill
- performance-optimizationSkill
- planning-and-task-breakdownSkill
- security-and-hardeningSkill
- shipping-and-launchSkill
- source-driven-developmentSkill
- spec-driven-developmentSkill
- addyosmani-tddSkill
- using-agent-skillsSkill
- apple-notesSkill
- apple-remindersSkill
- findmySkill
- imessageSkill
- claude-codeSkill
- codexSkill
- hermes-agentSkill
- opencodeSkill
- architecture-diagramSkill
- ascii-artSkill
- ascii-videoSkill
- baoyu-comicSkill
- baoyu-infographicSkill
- claude-designSkill
- comfyuiSkill
- creative-ideationSkill
- design-mdSkill
- drawio-headlessSkill
- excalidrawSkill
- humanizerSkill
- manim-videoSkill
- p5jsSkill
- pixel-artSkill
- popular-web-designsSkill
- pretextSkill
- sketchSkill
- social-media-slideshow-videoSkill
- songwriting-and-ai-musicSkill
- touchdesigner-mcpSkill
- visual-assets-generationSkill
- jupyter-live-kernelSkill
- api-monitoring-botsSkill
- cloud-browser-automationSkill
- docker-composeSkill
- kanban-orchestratorSkill
- kanban-workerSkill
- tinyfish-integrationSkill
- vps-cleanupSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 10 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 82
Solution: Use web console to add SSH key first (see Option 1 above).
- Distinctive: line 246
CRITICAL: If user says "keep password" or "tanpa ssh key" or similar:
- Distinctive: line 266
Always check current connection method first
- Distinctive: line 267
If password login, keep it enabled
- Distinctive: line 268
Only disable if user has working SSH keys AND explicitly requests it
- Very specific: line 275
Always run sudo sshd -t before reload
- Very specific: line 276
Use reload not restart (preserves current connections)
- Distinctive: line 284
Consider whitelist for user's known IPs (optional)
- Distinctive: line 294
Don't revisit unless user asks
- Very specific: line 301
Check if user has sudo privileges: sudo grep lighthouse /etc/sudoers.d/*
- Distinctive: line 302
If yes, it's emergency access mechanism
- Distinctive: line 303
DO NOT delete (user might need it for recovery)
- Distinctive: line 326
Only enable if user requests or if no cloud-level firewall exists.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
VPS Security Hardening
Audit and harden VPS security with fail2ban (brute-force protection), SSH hardening, and optional firewall setup.
When to Use
- New VPS setup (initial hardening)
- Security audit requested
- SSH brute-force attacks detected
- User wants to "secure VPS" or "protect server"
Prerequisites: Establishing SSH Access
Before hardening, ensure you can SSH into the VPS.
If Password Auth is Disabled (PublicKey only)
VPS providers often disable password auth by default. You need to add your SSH key first.
Option 1: Via VPS Web Console (Recommended)
- Generate SSH key locally (if not exists):
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N '' -C "user@machine" cat ~/.ssh/id_ed25519.pub - Login to VPS via web console (provider dashboard → Console/Terminal)
- 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 - Test from local machine:
ssh root@VPS_IP
Option 2: Via Provider Dashboard
Most providers (DigitalOcean, Vultr, Biznet, etc.) have "Add SSH Key" in dashboard:
- Copy public key (
cat ~/.ssh/id_ed25519.pub) - Paste into provider's SSH key management
- Rebuild/restart VPS (some providers require this)
Option 3: Enable Password Auth Temporarily
Only if web console is unavailable:
- Login via web console
- Edit SSH config:
echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config.d/99-temp-password.conf systemctl reload sshd - SSH in with password, add your key
- Remove temp config:
rm /etc/ssh/sshd_config.d/99-temp-password.conf systemctl reload sshd
Common Pitfall: sshpass with PublicKey-Only VPS
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).
Workflow
Phase 1: Security Audit
- Check running processes
ps aux --sort=-%mem | head -20 systemctl list-units --type=service --state=running - Check listening ports
sudo ss -tulpn sudo netstat -tulpn - 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 - Check user accounts
cat /etc/passwd | grep -E '/bin/(bash|sh)$' sudo lastlog - Resource usage
free -h df -h uptime
Phase 2: Install fail2ban
# Install
sudo apt-get update
sudo apt-get install -y fail2ban
# Enable and start
sudo systemctl enable fail2ban
sudo systemctl start fail2banPhase 3: Configure 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 = 5Restart:
sudo systemctl restart fail2ban
sudo fail2ban-client status sshdPhase 4: SSH Hardening
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-sha256Test and reload:
sudo sshd -t
sudo systemctl reload sshdPhase 5: Verify
# 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 banipImportant: Password vs SSH Key Decision
DO NOT automatically disable password authentication!
Check First
# Check if user has SSH keys
cat ~/.ssh/authorized_keys
# Check how user is currently connected
sudo grep "Accepted" /var/log/auth.log | tail -5Decision Logic
If user logs in with PASSWORD:
- ✅ Keep
PasswordAuthentication yes - ✅ fail2ban provides brute-force protection
- ⚠️ Disabling password = user gets locked out
If user logs in with SSH KEY:
- ✅ Can disable
PasswordAuthentication no - ✅ Maximum security (impossible to brute-force)
User Preference Handling
CRITICAL: If user says "keep password" or "tanpa ssh key" or similar:
- ✅ Accept their decision
- ✅ Explain security is already good with fail2ban
- ❌ DO NOT keep suggesting SSH keys
- ❌ DO NOT say "but SSH keys are better"
- ❌ DO NOT make them feel their choice is wrong
User knows their use case better than you:
- They might need portability (login from anywhere)
- They might not want key file management
- They might prefer convenience over maximum security
- Respect their decision and move on
Pitfalls
1. Disabling Password Auth Too Early
Problem: User currently uses password, you disable it, user gets locked out.
Solution:
- Always check current connection method first
- If password login, keep it enabled
- Only disable if user has working SSH keys AND explicitly requests it
2. Not Testing SSH Config
Problem: Invalid SSH config breaks SSH service, user locked out.
Solution:
- Always run
sudo sshd -tbefore reload - Use
reloadnotrestart(preserves current connections)
3. fail2ban Banning User's Own IP
Problem: User makes typo 5 times, gets banned.
Solution:
- Explain how to unban via VPS console:
sudo fail2ban-client unban --all - Consider whitelist for user's known IPs (optional)
4. Over-Suggesting Security Improvements
Problem: User made decision (e.g., keep password), you keep suggesting alternatives.
Solution:
- Present options ONCE with pros/cons
- User decides
- Accept decision and move on
- Don't revisit unless user asks
5. Cloud Provider Default Users
Problem: Deleting cloud provider system users (e.g., lighthouse on Tencent Cloud).
Solution:
- Check if user has sudo privileges:
sudo grep lighthouse /etc/sudoers.d/* - If yes, it's emergency access mechanism
- DO NOT delete (user might need it for recovery)
Monitoring Commands
# Check fail2ban status
sudo fail2ban-client status sshd
# Check banned IPs
sudo fail2ban-client get sshd banip
# Unban IP
sudo fail2ban-client set sshd unbanip 1.2.3.4
# Watch SSH attacks live
sudo journalctl -u ssh -f
# Recent failed attempts
sudo grep "Failed password" /var/log/auth.log | tail -20Optional: UFW Firewall
Only enable if user requests or if no cloud-level firewall exists.
# Allow SSH first (CRITICAL!)
sudo ufw allow 22/tcp
# Allow other services
sudo ufw allow 1430/tcp # Example: API port
# Enable
sudo ufw enable
# Check status
sudo ufw statusSuccess Criteria
- ✅ fail2ban running and banning attackers
- ✅ SSH hardened (root disabled, limited attempts)
- ✅ User can still login (not locked out)
- ✅ Auto-updates enabled
- ✅ User satisfied with security level
References
references/ssh-key-vs-password.md— Detailed comparison and decision framework- fail2ban docs: https://www.fail2ban.org/
- SSH hardening guide: https://www.ssh.com/academy/ssh/sshd_config
- Ubuntu security: https://ubuntu.com/security
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

