agentleFS
MathiasPaulenkoMathiasPaulenko/ai-toolkit/skills/paramiko-ssh/SKILL.md

paramiko-ssh

Skill2 starsChanged 4 months agoMITView on GitHub

SSH automation with Paramiko. Covers connection handling, command execution, file transfer (SFTP), key-based auth, bastion hosts, and async patterns for remote server management.

  • Reads credentials

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    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. Very specific:

    Always close connections (with or finally).

    line 141
  2. Very specific:

    Use AutoAddPolicy() only in dev.

    line 142
  3. Very specific:

    Use get_pty=True only when needed (adds overhead).

    line 146

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

Paramiko SSH

1. Connection Setup

Basic Password Auth

import paramiko

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname='192.168.1.10', username='admin', password='secret')

Key-Based Auth

client.connect(
    hostname='192.168.1.10',
    username='admin',
    key_filename='/home/user/.ssh/id_rsa',
    # Or load key from string/memory
    pkey=paramiko.RSAKey.from_private_key_file('/home/user/.ssh/id_rsa'),
)

Connection Manager (Context Manager)

from contextlib import contextmanager

@contextmanager
def ssh_client(hostname, username, key_filename):
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        client.connect(hostname=hostname, username=username, key_filename=key_filename)
        yield client
    finally:
        client.close()

with ssh_client('192.168.1.10', 'admin', '~/.ssh/id_rsa') as client:
    stdin, stdout, stderr = client.exec_command('uptime')
    print(stdout.read().decode())

2. Command Execution

Simple Commands

stdin, stdout, stderr = client.exec_command('df -h')
output = stdout.read().decode()
errors = stderr.read().decode()

Sudo Commands

stdin, stdout, stderr = client.exec_command('sudo -S systemctl restart nginx')
stdin.write('sudo_password\n')
stdin.flush()
print(stdout.read().decode())

Streaming Output

stdin, stdout, stderr = client.exec_command('tail -f /var/log/app.log', get_pty=True)
for line in iter(stdout.readline, ''):
    print(line, end='')

3. SFTP File Transfer

with client.open_sftp() as sftp:
    # Upload
    sftp.put('local/file.txt', '/remote/file.txt')
    # Download
    sftp.get('/remote/file.txt', 'local/file.txt')
    # List directory
    for entry in sftp.listdir('/var/log'):
        print(entry)
    # Create remote directory
    sftp.mkdir('/remote/new_dir')
    # Remove remote file
    sftp.remove('/remote/old_file.txt')

4. Bastion / Jump Host

# Connect to bastion first
bastion = paramiko.SSHClient()
bastion.set_missing_host_key_policy(paramiko.AutoAddPolicy())
bastion.connect('bastion.example.com', username='jumpuser', key_filename='~/.ssh/bastion')

# Open channel through bastion to target
vm_transport = bastion.get_transport()
dest_addr = ('target.internal', 22)
local_addr = ('127.0.0.1', 0)
channel = vm_transport.open_channel('direct-tcpip', dest_addr, local_addr)

# Connect to target through the channel
target = paramiko.SSHClient()
target.set_missing_host_key_policy(paramiko.AutoAddPolicy())
target.connect('target.internal', username='admin', sock=channel)

stdin, stdout, stderr = target.exec_command('hostname')
print(stdout.read().decode())

5. Async with AsyncSSH

import asyncssh
import asyncio

async def run_remote(host, command):
    async with asyncssh.connect(host, username='admin', client_keys=['~/.ssh/id_rsa']) as conn:
        result = await conn.run(command)
        return result.stdout, result.stderr, result.exit_status

output, errors, code = asyncio.run(run_remote('server1', 'uptime'))

6. Best Practices

  • Always close connections (with or finally).
  • Use AutoAddPolicy() only in dev; use RejectPolicy() + known_hosts in prod.
  • Load keys from environment/secrets, not hardcoded strings.
  • Set timeout and banner_timeout for network resilience.
  • Log all commands for audit trails.
  • Use get_pty=True only when needed (adds overhead).

7. Common Patterns

Parallel Execution on Multiple Hosts

from concurrent.futures import ThreadPoolExecutor

def run_on_host(host, command):
    with ssh_client(host, 'admin', '~/.ssh/id_rsa') as client:
        _, stdout, _ = client.exec_command(command)
        return host, stdout.read().decode()

hosts = ['web1', 'web2', 'web3']
command = 'systemctl status nginx'

with ThreadPoolExecutor(max_workers=10) as pool:
    results = pool.map(lambda h: run_on_host(h, command), hosts)

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.