Documentation ¶
Overview ¶
Package sshtun provides a SSH tunnel with port forwarding. By default it reads the default linux ssh private key location ($HOME/.ssh/id_rsa).
Index ¶
- type ConnState
- type Endpoint
- type SSHTun
- func (tun *SSHTun) SetConnState(connStateFun func(*SSHTun, ConnState))
- func (tun *SSHTun) SetDebug(debug bool)
- func (tun *SSHTun) SetKeyFile(file string)
- func (tun *SSHTun) SetLocalHost(host string)
- func (tun *SSHTun) SetPassword(password string)
- func (tun *SSHTun) SetPort(port int)
- func (tun *SSHTun) SetRemoteHost(host string)
- func (tun *SSHTun) SetTimeout(timeout time.Duration)
- func (tun *SSHTun) SetUser(user string)
- func (tun *SSHTun) Start() error
- func (tun *SSHTun) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnState ¶
type ConnState int
ConnState represents the state of the SSH tunnel. It's returned to an optional function provided to SetConnState.
const ( // StateStopped represents a stopped tunnel. A call to Start will make the state to transition to StateStarting. StateStopped ConnState = iota // StateStarting represents a tunnel initializing and preparing to listen for connections. // A successful initialization will make the state to transition to StateStarted, otherwise it will transition to StateStopped. StateStarting // StateStarted represents a tunnel ready to accept connections. // A call to stop or an error will make the state to transition to StateStopped. StateStarted )
type SSHTun ¶
SSHTun represents a SSH tunnel
func New ¶
New creates a new SSH tunnel to the specified server redirecting a port on local localhost to a port on remote localhost. By default the SSH connection is made to port 22 as root and using the default linux private key location ($HOME/.ssh/id_rsa). Calling SetPassword will change the authentication to password based and with SetKeyFile another key can be specified. The SSH user and port can be changed with SetUser and SetPort. The local and remote hosts can be changed to something different than localhost with SetLocalHost and SetRemoteHost. The states of the tunnel can be received throgh a callback function with SetConnState.
func (*SSHTun) SetConnState ¶
SetConnState specifies an optional callback function that is called when a SSH tunnel changes state. See the ConnState type and associated constants for details.
func (*SSHTun) SetKeyFile ¶
SetKeyFile changes the authentication to key-based and uses the specified file. Leaving it empty defaults to the default linux private key location ($HOME/.ssh/id_rsa).
func (*SSHTun) SetLocalHost ¶
SetLocalHost sets the local host to redirect (defaults to localhost)
func (*SSHTun) SetPassword ¶
SetPassword changes the authentication to password-based and uses the specified password.
func (*SSHTun) SetRemoteHost ¶
SetRemoteHost sets the remote host to redirect (defaults to localhost)
func (*SSHTun) SetTimeout ¶
SetTimeout sets the connection timeouts (defaults to 15 seconds).