Registry / testing / mock-ssh-server

mock-ssh-server

JSON →
library0.9.1pypypi✓ verified 83d ago

mock-ssh-server is a Python library providing a mock SSH server for testing purposes. It allows developers to create controlled SSH environments to test clients without needing a real SSH server. The current version is 0.9.1, and it generally follows an infrequent release cadence, driven by feature additions and bug fixes.

pip install mock-ssh-server
INSTALL
IMPORT
SIG · MOCK-SSH-SERVER
M
mock-ssh-server
testingpythonv0.9.1
Install
3.1s avg
Import
Disk
40MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 41.9MB
glibc
py 3.103.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.")
Debug
Known issues
gotchaVersions prior to 0.3.0 were known to experience occasional deadlocks, particularly when interacting with real OpenSSH clients. This could lead to testing hangs or instability.
fix
Upgrade to mock-ssh-server version 0.3.0 or newer to resolve deadlock issues.
affects: <0.3.0
gotchaBefore version 0.9.0, customizing the authentication class was not directly supported via the API. Users might have resorted to workarounds or found their customization options limited.
fix
Upgrade to version 0.9.0 or later to leverage the new authentication class override feature, allowing for more flexible authentication strategies.
affects: <0.9.0
gotchaWhen generating host keys (e.g., `paramiko.RSAKey.generate()`), `mock-ssh-server` implicitly relies on `paramiko`'s underlying dependencies like `cryptography`. Missing or misconfigured `cryptography` installations can lead to errors during key generation.
fix
Ensure `cryptography` is correctly installed. If encountering issues, try `pip install cryptography` explicitly, or ensure your environment has the necessary build tools for it.
affects: All versions
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.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
mock-ssh-server — pip install mock-ssh-server · libregistry