Skip to content

Instantly share code, notes, and snippets.

@will
Created August 3, 2020 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save will/d0b7fcc5be61b6cebd649ca39f474886 to your computer and use it in GitHub Desktop.
Save will/d0b7fcc5be61b6cebd649ca39f474886 to your computer and use it in GitHub Desktop.
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