Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SSH tunneling to pxssh #473

Merged
merged 5 commits into from Mar 24, 2018
Merged

Add SSH tunneling to pxssh #473

merged 5 commits into from Mar 24, 2018

Conversation

Red-M
Copy link
Member

@Red-M Red-M commented Mar 17, 2018

I had to backport in a command line sanitizer from shlex.quote so that python2 would function correctly with no shell injection.

@Red-M
Copy link
Member Author

Red-M commented Mar 17, 2018

This code should let you see what and how to use this.

#!/usr/bin/env python2
import pexpect
import getpass
from pexpect import pxssh

s = pxssh.pxssh()
hostname = raw_input('hostname: ')
username = raw_input('username: ')
password = getpass.getpass('password: ')


ssh_tunnels = {
'local':['2424:localhost:22'],
'remote':['2525:localhost:22']
}


s.login(hostname, username, password, ssh_key=True, ssh_tunnels=ssh_tunnels)
s.sendline('w')
s.prompt()
print('This should list the remote SSH server\'s logged in users')
print(s.before)

print('Testing Local SSH tunnel')
s2 = pxssh.pxssh()
s2.login('localhost', username, password, port=2424, ssh_key=True,quiet=False)
s2.sendline('w')
s2.prompt()
print('This should list the remote SSH server\'s logged in users plus our new connection.')
print(s2.before)

print('Testing Remote SSH tunnel')
s.login('localhost', username, password, port=2525, ssh_key=True,quiet=False,spawn_local_ssh=False)
s.sendline('w')
s.prompt()
print('This should list the local machine\'s logged in users')
print(s.before)

Fix a bug with chaining SSH sessions and providing an SSH key.
@Red-M Red-M merged commit 1b84ed2 into pexpect:master Mar 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant