import asyncio, sys, subprocess, os, fcntl, struct, termios, logging, asyncssh, time logger = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG) async def handle_client(process: asyncssh.SSHServerProcess) -> None: local_pty, local_tty = os.openpty() local_proc = subprocess.Popen('./script.sh', shell=True, stdin=local_pty, stdout=local_pty, stderr=local_pty) os.close(local_pty) await process.redirect(stdin=local_tty, stdout=os.dup(local_tty)) await process.stdout.drain() process.exit(0) await process.wait_closed() async def start_server() -> None: await asyncssh.listen('127.0.0.1', 8022, server_host_keys=['ssh_host_key'], authorized_client_keys='ssh_user_ca',line_editor=False, process_factory=handle_client) loop = asyncio.get_event_loop() try: loop.run_until_complete(start_server()) except (OSError, asyncssh.Error) as exc: sys.exit('Error starting server: ' + str(exc)) try: loop.run_forever() except KeyboardInterrupt as exc: sys.exit('Program stopped')