Install & Compatibility
Where this runs
tested against v0.9.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 41.9MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.1s · import 0.000s · 42MB
40MB installed
● package 40MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Server
✓ from mockssh import Server
✗ from mockssh import MockSSH
This quickstart demonstrates how to set up a mock SSH server with defined users and then connects to it using a Paramiko SSH client to execute a simple command. This confirms the server is operational and authentication works.
import paramiko
from mockssh import MockSSH
import socket # For example error handling
# 1. Define users for the mock SSH server
users = {
"testuser": "testpassword",
"admin": "securepass"
}
# 2. Generate a host key for the server (essential for real SSH clients)
# In a real application, you might load a persistent key.
server_host_key = paramiko.RSAKey.generate(2048)
print("Starting Mock SSH server...")
# 3. Start the mock SSH server in a context manager
with MockSSH(users, host='127.0.0.1', rsa_key=server_host_key) as s:
server_port = s.port
print(f"Mock SSH server running on 127.0.0.1:{server_port}")
# 4. Demonstrate a client connection using paramiko
print("\nAttempting to connect with Paramiko client...")
client = paramiko.SSHClient()
# Automatically add new host keys (for testing, not recommended for production)
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(
hostname='127.0.0.1',
port=server_port,
username='testuser',
password='testpassword'
)
print("Client connected successfully to mock SSH server.")
# Execute a simple command
stdin, stdout, stderr = client.exec_command('echo "Hello from mock SSH client!"')
output = stdout.read().decode().strip()
error = stderr.read().decode().strip()
print(f"Command output: '{output}'")
if error:
print(f"Command error: '{error}'")
except paramiko.AuthenticationException:
print("Authentication failed for 'testuser'! Check username/password.")
except paramiko.SSHException as e:
print(f"SSH connection failed: {e}")
except socket.error as e:
print(f"Socket error: {e}. Is the server running and accessible?")
except Exception as e:
print(f"An unexpected error occurred: {e}")
finally:
if client.get_transport() and client.get_transport().is_active():
client.close()
print("Client connection closed.")
print("Mock SSH server context manager exited. Server is stopped.")
Upgrade
Version history
0.9.1latest on PyPI · released Sep 13, 2021
Audit
Dependencies
paramikorequiredCore library for SSH protocol implementation.
pyasn1requiredASN.1 library, a dependency of paramiko.
cryptographyrequiredCryptographic primitives, a dependency of paramiko, often required for key generation.