Emulate an Interactive SSH client using Paramiko / Twisted

2.2k Views Asked by At

I need to emulate SSH client and log the entered commands.

I have followed different links but most of the examples are related to automating tasks. For testing purpose, I need to emulate an Interative SSH Session and log commands.

Note: Paramiko is not mandatory. Twisted resources are much appreciated

1

There are 1 best solutions below

0
Martin Prikryl On BEST ANSWER

Use Channel.get_pty and Channel.invoke_shell to simulate an interactive SSH terminal session.

sshClient = paramiko.SSHClient()
sshClient.connect(host, username=user, password=pass)
channel = sshClient.get_transport().open_session()

# Open interactive SSH session
channel.get_pty()
channel.invoke_shell()

print('Executing command 1')    
channel.send('command 1\n')

print('Executing command 2')
channel.send('command 2\n')