View Source ssh_tunnel (util v1.1.5)
Link to this section Summary
Functions
Module for creating SSH tunnels using ssh
. https://github.com/drowzy/ssh_tunnel
ssh_connect/3
and does not support all options. returns: {ok, Connection}
or {error, Reason}
. https://manpages.debian.org/stretch/erlang-manpages/ssh.3erl.en.htmlssh:connect/4
) can be used to send messages with ssh_connection:send/3
. returns: {ok, Channel}` or `{error, Reason}
. Ex: msg = "GET /images/json HTTP/1.1\r\nHost: /var/run/docker.sock\r\nAccept: */*\r\n\r\n"
{ok, Pid} = ssh_tunnel:connect("192.168.90.15", 22),
{ok, Ch} = ssh_tunnel:direct_stream_local(Pid, "/var/run/docker.sock"),
ok = ssh_connection.send(Pid, Ch, Msg)
:ssh.connect/4
) can be used to send messages with ssh_connection:send/3
returns: {ok, channel}
or {error, reason}
. ## Examples: msg = "GET / HTTP/1.1\r\nHost: localhost:8080\r\nUser-Agent: curl/7.47.0\r\nAccept: */*\r\n\r\n" {ok, Pid} = ssh_tunnel:connect("192.168.1.10", 22), {ok, Ch} = ssh_tunnel:direct_tcpip(Pid, {"127.0.0.1", 8080}, {"192.168.1.10", 80}), ok = ssh_connection:send(Pid, Ch, Msg), recieve do {ssh_cm, _, {data, Channel, _, Data}} -> io:format("Data: ~p\n", [Data]) endLink to this section Types
-type location() :: {string(), integer()}.
Link to this section Functions
Module for creating SSH tunnels using ssh
. https://github.com/drowzy/ssh_tunnel
It provides functions to create forwarded ssh channels, similair to how other channels can be created using ssh_connection
. There are two type of channels supported * directtcp-ip` - Forwards a port from the client machine to the remote machine. This is the same as `ssh -nNT -L 8080:forward.example.com:9000 user@sshserver.example.com
* direct-streamlocal
- Forwards to a unix domain socket. This is the same as ssh -nNT -L 8080:/var/lib/mysql/mysql.sock user@sshserver.example.com
When using direct_tcpip/3
or direct_stream_local/2
directly there will not be any local port or socket bound, this can either be done using ssh_tunnel
or by manually sending data with ssh_connection.send/3
. Although connect/1
can be used to connect to the remote host, other methods are supported. One can use [SSHex](https://github.com/rubencaro/sshex), ssh:connect/3
for instance.
## Tunnels Tunnels are on-demand TCP servers and are bound listeners to either a port or a path. The tunnel will handle relaying TCP messages to the ssh connection and back.
## Examples {ok, SshRef} = ssh_tunnel:connect("sshserver.example.com", 22, []),
{ok, Pid} = ssh_tunnel:start_tunnel(Pid, {tcpip, {8080, {"192.168.90.15", 80}}}),
% Send a TCP message for instance HTTP
Resp = HTTPoison.get!("127.0.0.1:8080"),
io:format("Received body: ~p\n", [Resp])
-spec connect(list() | tuple(), integer(), list()) -> {ok, pid()} | {error, term()}.
ssh_connect/3
and does not support all options. returns: {ok, Connection}
or {error, Reason}
. https://manpages.debian.org/stretch/erlang-manpages/ssh.3erl.en.html
-spec direct_stream_local(pid(), string()) -> {ok, integer()} | {error, term()}.
ssh:connect/4
) can be used to send messages with ssh_connection:send/3
. returns: {ok, Channel}` or `{error, Reason}
. Ex: msg = "GET /images/json HTTP/1.1\r\nHost: /var/run/docker.sock\r\nAccept: */*\r\n\r\n"
{ok, Pid} = ssh_tunnel:connect("192.168.90.15", 22),
{ok, Ch} = ssh_tunnel:direct_stream_local(Pid, "/var/run/docker.sock"),
ok = ssh_connection.send(Pid, Ch, Msg)
-spec direct_tcpip(pid(), From :: location(), To :: location()) -> {ok, integer()} | {error, term()}.
:ssh.connect/4
) can be used to send messages with ssh_connection:send/3
returns: {ok, channel}
or {error, reason}
. ## Examples: msg = "GET / HTTP/1.1\r\nHost: localhost:8080\r\nUser-Agent: curl/7.47.0\r\nAccept: */*\r\n\r\n" {ok, Pid} = ssh_tunnel:connect("192.168.1.10", 22), {ok, Ch} = ssh_tunnel:direct_tcpip(Pid, {"127.0.0.1", 8080}, {"192.168.1.10", 80}), ok = ssh_connection:send(Pid, Ch, Msg), recieve do {ssh_cm, _, {data, Channel, _, Data}} -> io:format("Data: ~p\n", [Data]) end
-spec start_tunnel(pid(), tcp | local, tuple() | integer()) -> {ok, pid()} | {error, term()}.