Skip to content

Instantly share code, notes, and snippets.

@will
Created August 3, 2020 17:14
net::ssh remote port to local socket
# on remote machine
# nc -l -p 1212
# on local machine
ssh = Net::SSH.start(remote.ip, "centos", keys_only: true, key_data: [remote.ssh_key])
tempfile = Tempfile.new("net_ssh_forward_test")
path = tempfile.path
tempfile.delete
us = UNIXServer.open(path)
ssh.forward.local(us, 'localhost', 1212)
client = UNIXSocket.new(us.path)
client.puts "hello world"
ssh.loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment