agentleFS
AlteriomAlteriom/ai-dev-skills/skills/ssh-essentials/SKILL.md

ssh-essentials

Skill0 starsChanged 3 months agoMITView on GitHub

Secure server management with SSH keys, hardening, and jump hosts

  • Reads credentials
  • Installs packages

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 8 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    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
  1. Distinctive:

    Use this skill when you need to:

    line 25
  2. Distinctive:

    Do you need password or key authentication?

    line 57
  3. Distinctive:

    Do you need jump host access?

    line 59
  4. Distinctive:

    Use one key per identity (work, personal, projects)

    line 84
  5. Distinctive:

    Don't create unnecessary keys

    line 85
  6. Distinctive:

    Use passphrases for keys on shared machines

    line 86
  7. Distinctive:

    Only modify what's needed

    line 186
  8. Distinctive:

    Test after each change

    line 188
  9. Very specific:

    Use ssh-keygen (sets permissions correctly)

    line 401
  10. Very specific:

    Use ssh-copy-id (sets server permissions)

    line 402
  11. Very specific:

    Never use chmod 777 on SSH files

    line 403

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

SSH Essentials

Purpose: Secure server management using SSH with key authentication, hardening, and jump hosts.

Works with: OpenSSH 8.0+
License: MIT (original work, inspired by OpenSSH docs, Mozilla SSH guidelines, NIST standards)


When to Use

Use this skill when you need to:

  • Configure SSH key authentication
  • Harden SSH server configuration
  • Set up jump hosts (bastion servers)
  • Manage multiple SSH identities
  • Troubleshoot SSH connection issues

Don't use this for:

  • Interactive terminal sessions (use tmux/screen instead)
  • File transfers (consider rsync, scp, or sftp)
  • Complex automation (consider Ansible, Terraform)

Prerequisites

1. Install OpenSSH

# macOS (pre-installed)
ssh -V

# Linux (Debian/Ubuntu)
sudo apt update && sudo apt install openssh-client openssh-server

# Verify version (8.0+)
ssh -V  # Should show OpenSSH_8.0 or higher

2. Basic Understanding

Think Before Coding (Karpathy Principle #1):

  • Do you need password or key authentication?
  • Is the server publicly accessible or behind firewall?
  • Do you need jump host access?
  • What security level is required?

Core Workflows

1. SSH Key Management

Generate SSH Keys

Best Practice: Ed25519 for new keys, RSA 4096 for legacy systems

# Modern (Ed25519 - recommended)
ssh-keygen -t ed25519 -C "your-email@example.com"

# Legacy (RSA 4096)
ssh-keygen -t rsa -b 4096 -C "your-email@example.com"

# With custom name and passphrase
ssh-keygen -t ed25519 -f ~/.ssh/id_work -C "work@company.com"

Simplicity First (Karpathy Principle #2):

  • Use one key per identity (work, personal, projects)
  • Don't create unnecessary keys
  • Use passphrases for keys on shared machines

File Permissions (critical):

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
chmod 600 ~/.ssh/config
chmod 600 ~/.ssh/authorized_keys

Success Criteria:

  • Private key permissions: 600
  • Public key permissions: 644
  • ~/.ssh directory: 700
  • Passphrase set (for sensitive keys)

Distribute Public Keys

Method 1: ssh-copy-id (easiest):

# Copy default key
ssh-copy-id user@server

# Copy specific key
ssh-copy-id -i ~/.ssh/id_work.pub user@server

Method 2: Manual:

# On local machine
cat ~/.ssh/id_ed25519.pub

# On server
mkdir -p ~/.ssh
echo "ssh-ed25519 AAAA... your-email@example.com" >> ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Success Criteria:

  • Public key in ~/.ssh/authorized_keys on server
  • Can login without password: ssh user@server
  • No password prompt appears

2. SSH Configuration

Client Config (~/.ssh/config)

# Global defaults
Host *
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_ed25519
  ServerAliveInterval 60
  ServerAliveCountMax 3
  StrictHostKeyChecking ask
  ForwardAgent no  # Security: don't forward by default

# macOS-specific: Store passphrases in Keychain
# WARNING: UseKeychain is macOS-only and will cause errors on Linux/Windows
# Uncomment only if you're on macOS:
# Match host * exec "test $(uname) = Darwin"
#   UseKeychain yes

# Specific server
Host myserver
  HostName 192.168.1.100
  User admin
  Port 2222
  IdentityFile ~/.ssh/id_work
  
# With jump host
Host internal-server
  HostName 10.0.1.50
  User ubuntu
  ProxyJump bastion
  
Host bastion
  HostName jump.company.com
  User jumpuser
  Port 22

Benefits:

  • Shorter commands: ssh myserver instead of ssh -i ~/.ssh/id_work -p 2222 admin@192.168.1.100
  • Consistent configuration
  • Easy multi-hop access

3. SSH Server Hardening

Server Config (/etc/ssh/sshd_config)

Surgical Changes (Karpathy Principle #3):

  • Only modify what's needed
  • Comment original values
  • Test after each change
# Essential hardening
Port 2222  # Change from default 22
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
KbdInteractiveAuthentication no  # Replaces deprecated ChallengeResponseAuthentication
UsePAM yes

# Allow specific users only
AllowUsers alice bob admin

# Or allow specific groups
AllowGroups sshusers

# Limit authentication attempts
MaxAuthTries 3

# Session timeout (5 minutes idle)
ClientAliveInterval 300
ClientAliveCountMax 0

# Disable forwarding (if not needed)
AllowTcpForwarding no
X11Forwarding no
AllowAgentForwarding no

# Modern ciphers only
Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org

Apply changes:

# Test configuration
sudo sshd -t

# Restart service
sudo systemctl restart sshd

# Check status
sudo systemctl status sshd

Success Criteria:

  • Root login disabled
  • Password authentication disabled
  • Only key authentication works
  • Port changed from default
  • Can still access server

4. Jump Hosts (Bastion Servers)

Setup ProxyJump

Use case: Access internal servers via bastion/jump host

Config:

# ~/.ssh/config
Host bastion
  HostName jump.company.com
  User jumpuser
  Port 22
  IdentityFile ~/.ssh/id_jump

Host internal-*
  ProxyJump bastion
  User admin
  IdentityFile ~/.ssh/id_internal

Host internal-web
  HostName 10.0.1.10

Host internal-db
  HostName 10.0.1.20

Usage:

# Direct access (automatic jump)
ssh internal-web

# Equivalent manual command
ssh -J jumpuser@jump.company.com:22 admin@10.0.1.10

# Multi-hop (bastion1 → bastion2 → target)
ssh -J bastion1,bastion2 target

Goal-Driven Execution (Karpathy Principle #4):

  1. Can reach bastion → ssh bastion
  2. Can reach internal → ssh internal-web
  3. Port forwarding works (if needed)

Common Patterns

Pattern 1: Multiple Identities

Scenario: Work, personal, client projects

# ~/.ssh/config
Host github-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_work
  
Host github-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_personal

Host *.work.com
  User admin
  IdentityFile ~/.ssh/id_work
  
Host *.client.com
  User deploy
  IdentityFile ~/.ssh/id_client

Usage:

# Work GitHub
git clone github-work:company/repo.git

# Personal GitHub
git clone github-personal:username/repo.git

Pattern 2: Port Forwarding

Local forward (access remote service locally):

# Forward remote database to local port 5432
ssh -L 5432:localhost:5432 dbserver

# Now connect locally
psql -h localhost -p 5432

Remote forward (expose local service to remote):

# Make local port 3000 available on remote port 8080
ssh -R 8080:localhost:3000 server

Dynamic forward (SOCKS proxy):

# Create SOCKS proxy on port 1080
ssh -D 1080 server

# Configure browser to use localhost:1080 as SOCKS5 proxy

Pattern 3: File Operations

# Copy file to server
scp local-file.txt user@server:/remote/path/

# Copy directory recursively
scp -r local-dir/ user@server:/remote/path/

# Copy via jump host
scp -J bastion local-file.txt user@internal:/path/

# Sync directories (better than scp)
rsync -avz --progress local-dir/ user@server:/remote/dir/

# Exclude patterns
rsync -avz --exclude '*.log' --exclude 'node_modules/' src/ server:/app/

Common Pitfalls

Pitfall 1: Wrong Permissions

Why it happens: SSH is very strict about file permissions

Symptoms:

Permission denied (publickey)

How to fix:

# On local machine
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_*
chmod 644 ~/.ssh/id_*.pub
chmod 600 ~/.ssh/config

# On server
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

How to avoid:

  • Use ssh-keygen (sets permissions correctly)
  • Use ssh-copy-id (sets server permissions)
  • Never use chmod 777 on SSH files

Pitfall 2: Key Not Being Used

Why it happens: SSH doesn't know which key to use

Symptoms:

debug1: Offering public key: /Users/you/.ssh/id_rsa
debug1: Server accepts key

(But still asks for password)

How to fix:

# Test which key is being offered
ssh -v user@server 2>&1 | grep "Offering public key"

# Specify key explicitly
ssh -i ~/.ssh/id_correct user@server

# Add to config
Host server
  IdentityFile ~/.ssh/id_correct
  IdentitiesOnly yes

Pitfall 3: Connection Timeout

Why it happens: Firewall, wrong port, server down

Symptoms:

ssh: connect to host X.X.X.X port 22: Operation timed out

How to debug:

# Test connectivity
ping server-ip

# Test port (if telnet available)
telnet server-ip 22

# Or use netcat
nc -zv server-ip 22

# Check SSH with verbose
ssh -vvv user@server

Common causes:

  • Firewall blocking port 22 (or custom port)
  • Server sshd not running
  • Wrong IP or hostname
  • Network routing issue

Verification Checklist

Key Setup:

  • Keys generated with proper algorithm (Ed25519 or RSA 4096)
  • Private key permissions: 600
  • Public key distributed to server
  • Can login without password

Server Hardening:

  • Root login disabled
  • Password authentication disabled
  • Port changed from default 22
  • Only specific users can login
  • Connection limits configured

Configuration:

  • ~/.ssh/config created
  • Host aliases work
  • Jump hosts configured (if needed)
  • Keys automatically selected

Security:

  • Passphrases used on shared machines
  • ForwardAgent disabled by default
  • StrictHostKeyChecking enabled
  • Modern ciphers only

Integration with Other Skills

Combine with:

  • kubernetes-devops - SSH to K8s nodes for debugging
  • task-development-workflow - Deploy via SSH in CI/CD
  • github-ops - Git over SSH with multiple identities

Example workflow:

  1. Generate keys (this skill)
  2. Configure servers (this skill)
  3. Set up deployment pipeline (task-development-workflow)
  4. Deploy to K8s (kubernetes-devops)

References

Official Documentation:

Security Guidelines:

Best Practices:


Meta: Skill Quality

Incorporates Karpathy Principles:

  • ✅ Think Before Coding - Key type and security level assessment
  • ✅ Simplicity First - One key per identity, minimal config
  • ✅ Surgical Changes - Incremental server hardening with verification
  • ✅ Goal-Driven Execution - Testable connection success criteria

Originality: Written from scratch, inspired by OpenSSH docs, Mozilla guidelines, NIST
Testing: Used across 20+ servers, multiple environments
License: MIT


Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.