ssh_tunnel (util v1.3.5)
View SourceSummary
Types
Module for creating SSH tunnels using ssh.
[https://github.com/drowzy/ssh_tunnel]
Functions
Create a connetion to a remote host with the provided options. This function is
mostly used as convenience wrapper around 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]
Creates a ssh stream local-forward channel to a remote unix domain socket. It
sends the request that the server make a connection to its local Unix domain
socket. The returned channel together with a ssh connection reference (returned
from ssh:connect/4) can be used to send messages with ssh_connection:send/3.
returns: {ok, Channel} or {error, Reason}. Ex
Creates a ssh directtcp-ip forwarded channel to a remote port. The returned
channel together with a ssh connection reference (returned from 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} =
sshtunnel: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
Starts a SSHTunnel.Tunnel process. The tunnel will listen to either a local port or local path and handle passing messages between the TCP client and ssh connection. ## Examples {ok, SSH} = ssh_tunnel:connect("sshserver.example.com", 22), {ok, Pid} = ssh_tunnel:start_tunnel(Pid, tcp, {8080, {"192.168.90.15", 80}}) # Send a TCP message %HTTPoison.Response{body: body} = HTTPoison.get!("127.0.0.1:8080") IO.puts("Received body: #{body})
Types
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 asssh -nNT -L 8080:forward.example.com:9000 user@sshserver.example.comdirect-streamlocal- Forwards to a unix domain socket. This is the same asssh -nNT -L 8080:/var/lib/mysql/mysql.sock user@sshserver.example.comWhen usingdirect_tcpip/3ordirect_stream_local/2directly there will not be any local port or socket bound, this can either be done usingssh_tunnelor by manually sending data withssh_connection:send/3. Althoughconnect/3can be used to connect to the remote host, other methods are supported. One can use SSHex,ssh:connect/3for 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])
Functions
Create a connetion to a remote host with the provided options. This function is
mostly used as convenience wrapper around 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]
Creates a ssh stream local-forward channel to a remote unix domain socket. It
sends the request that the server make a connection to its local Unix domain
socket. The returned channel together with a ssh connection reference (returned
from 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()}.
Creates a ssh directtcp-ip forwarded channel to a remote port. The returned
channel together with a ssh connection reference (returned from 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} =
sshtunnel: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
Starts a SSHTunnel.Tunnel process. The tunnel will listen to either a local port or local path and handle passing messages between the TCP client and ssh connection. ## Examples {ok, SSH} = ssh_tunnel:connect("sshserver.example.com", 22), {ok, Pid} = ssh_tunnel:start_tunnel(Pid, tcp, {8080, {"192.168.90.15", 80}}) # Send a TCP message %HTTPoison.Response{body: body} = HTTPoison.get!("127.0.0.1:8080") IO.puts("Received body: #{body})