Paramiko
Paramiko is a native Python SSHv2 protocol library, providing both client and server functionality. The current version is 4.0.0, released on March 28, 2026. It follows a regular release cadence, with updates and patches released as needed.
Warnings
- breaking In version 4.0.0, the default policy for handling unknown host keys has changed to AutoAddPolicy, which automatically adds unknown host keys to the local host key database. This may introduce security risks if not properly managed.
- gotcha The SSHClient.connect() method now requires the 'hostname', 'username', and 'password' parameters to be explicitly provided or set as environment variables. Omitting these will result in a TypeError.
Install
-
pip install paramiko
Imports
- SSHClient
from paramiko import SSHClient
- AutoAddPolicy
from paramiko import AutoAddPolicy
Quickstart
import os
from paramiko import SSHClient, AutoAddPolicy
# Set up SSH client
client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy())
# Connect to the server
client.connect(os.environ.get('SSH_HOST', 'hostname'), username=os.environ.get('SSH_USER', 'user'), password=os.environ.get('SSH_PASSWORD', 'password'))
# Execute a command
stdin, stdout, stderr = client.exec_command('ls')
print(stdout.read().decode())
# Close the connection
client.close()