Skip to content

A tunneling tool based on ssh protocol can be used for port forwarding.

License

Notifications You must be signed in to change notification settings

c3b2a7/sshtunnel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SSH Tunnel

GitHub GitHub Workflow Status GitHub go.mod Go version GitHub release (latest by date)

A tunneling tool based on ssh protocol can be used for port forwarding. No dependency and out of the box.

Features

  • support local,remote,dynamic ssh port forwarding
  • support ssh-key,password authentication method

Installation

Using curl/sh:

curl https://raw.githubusercontent.com/c3b2a7/sshtunnel/master/scripts/get-sshtunnel.sh | sh

See the help output for more options:

curl https://raw.githubusercontent.com/c3b2a7/sshtunnel/master/scripts/get-sshtunnel.sh | sh -s -- -h

From source:

go install github.com/c3b2a7/sshtunnel@latest

Manual

You can also download and extract the latest release from https://github.com/c3b2a7/sshtunnel/releases

Usage

./sshtunnel
Usage of ./sshtunnel:
  -config string
    	config file
  -v	show version information
  -verbose
    	verbose mode

Quick Start

At first, you need write a configuration like this:

{
  "target": "host:port",
  "username": "username",
  "private-key": "location of ssh private key",
  "passphrase": "private-key passphrase or password of username",
  "tunnels": [
    {
      "local": "127.0.0.1:13306",
      "remote": "172.16.0.14:3306",
      "mode": "local"
    },
    {
      "local": "127.0.0.1:8080",
      "remote": "0.0.0.0:18080",
      "mode": "remote"
    },
    {
      "local": "127.0.0.1:1080",
      "mode": "dynamic"
    }
  ]
}

and then, use the following command to start ssh tunnel:

./sshtunnel -config /path/to/config -verbose

after the tunnel is established:

connect to the remote MySQL service like connecting to the local:

mysql -h 127.0.0.1 -P 13306 -u root -p # in local

connect to local service in remote:

nc -l 8080 # in local
nc localhost 18080 # in remote

connect to dynamic addr using socks5 protocol via remote server:

curl -x socks5://localhost:1080 ip.sb # in local

LICENSE

MIT