{"library":"asyncssh","code":"import asyncio\nimport asyncssh\nimport os\n\nasync def run_client():\n    host = os.environ.get('SSH_HOST', 'localhost')\n    port = int(os.environ.get('SSH_PORT', 22))\n    username = os.environ.get('SSH_USERNAME', 'testuser')\n    password = os.environ.get('SSH_PASSWORD', '') # Or use client_keys=['/path/to/id_rsa']\n\n    try:\n        # Connect to the SSH server\n        conn = await asyncssh.connect(host, port=port, username=username, password=password)\n\n        # Run a command and get the result\n        result = await conn.run('echo \"Hello from AsyncSSH!\"', check=True)\n        print(f\"Command: {result.command}\")\n        print(f\"Stdout: {result.stdout.strip()}\")\n        print(f\"Stderr: {result.stderr.strip()}\")\n        print(f\"Return code: {result.returncode}\")\n\n        # Close the connection (async with handles this implicitly if used for conn)\n        conn.close()\n\n    except (asyncssh.Error, OSError) as exc:\n        print(f'SSH connection or command failed: {exc}')\n\nif __name__ == '__main__':\n    # Note: For 'localhost' testing, you might need a local SSH server configured\n    # to accept connections for the specified username/password or client_key.\n    # Example to run:\n    # SSH_HOST=your_ssh_server SSH_USERNAME=your_user SSH_PASSWORD=your_pass python your_script.py\n    asyncio.run(run_client())\n","lang":"python","description":"This quickstart demonstrates how to establish an SSH client connection to a remote host, run a command, and print its output using `asyncssh.connect` and `conn.run`. It uses environment variables for host, port, username, and password for secure testing. For local testing, ensure an SSH server is running and configured correctly.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}