Giter Site home page Giter Site logo

tunnel's Introduction

tunnel

Go Reference

Note that this library is experimental.

tunnel is a very simple library that allows you to create multi-hop SSH tunnels. From the endpoint of the tunnel you can then Dial() to create network connections, or you can Listen() for incoming connections.

This library uses the ssh-agent to load any keys you might need. If you need to load keys from files, let me know and I'll probably add support for it.

You are responsible for closing any connections or listeners you make. The tunnel doesn't keep track of any connections you might have opened.

You can create multiple connections through the same tunnel.

Typical use

Import

Add the folliwing import and run go mod tidy to add tunnel to your project.

import "github.com/borud/tunnel"

Creating the tunnel

tunnel, err := tunnel.Create(tunnel.Config{
    Hops: []string{
        "[email protected]:22",
        "[email protected]:22",
    },
})

Dial

You can Dial to create a new connection over the tunnel like so:

  conn, err := tunnel.Dial("tcp", "service.example.com:4711")

If everything went according to plan you now have a tunnel that terminates at inside.example.com (since it is the last hop) and connects from there to port 4711 on service.example.com

Listen

You can also listen on the remote endpoint.

listener, err := tunnel.Listen("tcp", ":80")

A note on Listen ports

When you want to Listen to remote ports that should be externally available, you have to make sure that the SSH daemon is configured to allow this. Please review the GatewayPorts configuration option in sshd_config. If you were too lazy to read this paragraph and are just looking for a cut and paste, the config is:

GatewayPorts yes

tunnel's People

Contributors

borud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

postmannen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.