Skip to main content

Initiate SSH tunnels

Project description

**Author**: Pahaz Blinov
**Repo**: https://github.com/pahaz/sshtunnel/

Inspired: https://github.com/jmagnusson/bgtunnel but it don`t work on windows.
See also: https://github.com/paramiko/paramiko/blob/master/demos/forward.py

Require `paramiko`.

# Install #

pip install sshtunnel

or

easy_install sshtunnel

# SSH tunnels to remote server #

Useful when you need to connect to local port on remote server throw ssh
tunnel. It works by opening a port forwarding ssh connection in the
background, using threads. The connection(s) are closed when explicitly
calling the `close` method of the returned SSHTunnelForwarder object.

----------------------------------------------------------------------

|
-------------| | |----------| |---------
LOCAL | | | REMOTE | | PRIVATE
SERVER | <== SSH ========> | SERVER | <== local ==> | SERVER
-------------| | |----------| |---------
|
FIREWALL

----------------------------------------------------------------------

Fig1: How to connect to PRIVATE SERVER throw SSH tunnel.


## Ex 1: ##

import sshtunnel

with sshtunnel.open(
(ssh_host, ssh_port),
ssh_host_key=None,
ssh_username=ssh_user,
ssh_password=ssh_password,
ssh_private_key=None,
remote_bind_address=(REMOTE_HOST, REMOTE_PORT)) as server:

def do_something(port):
pass

print "LOCAL PORT:", server.local_bind_port

do_something(server.local_bind_port)

## Ex 2: ##

from sshtunnel import SSHTunnelForwarder

server = SSHTunnelForwarder(
ssh_address=('pahaz.urfuclub.ru', 22),
ssh_username="pahaz",
ssh_password="secret",
remote_bind_address=('127.0.0.1', 5555))

server.start()

print(server.local_bind_port)
# work with `SECRET SERVICE` throw `server.local_bind_port`.

server.stop()

# CHANGELOG #

## v.0.0.1 ##
- `SSHTunnelForwarder` class
- `open` function

Project details


Release history Release notifications

History Node

0.1.4

History Node

0.1.3.1

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

History Node

0.0.8.2

History Node

0.0.8.1

History Node

0.0.8

History Node

0.0.7

History Node

0.0.6

History Node

0.0.5

History Node

0.0.4.4

History Node

0.0.4.3

History Node

0.0.4.2

History Node

0.0.4.1

History Node

0.0.4

History Node

0.0.3

History Node

0.0.2

This version
History Node

0.0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
sshtunnel-0.0.1.zip (8.9 kB) Copy SHA256 hash SHA256 Source None Jun 12, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page