is it possible to create an SSH tunnel in Ruby or Python without creating a local port?

StackOverflow https://stackoverflow.com/questions/13445625

  •  30-11-2021
  •  | 
  •  

I'm wanting to create an SSH tunnel to use for talking securely with a remote legacy application, but I don't want other local applications to be able to use it. Is this possible with Python and/or Ruby, perhaps using an in-memory handle to the tunnel that can be written to and read from like a normal socket handle?

有帮助吗?

解决方案

Latest versions of OpenSSH support the -W flag to connect stdio to a remote tcp port:

ssh ssh_host -W host:port

I don't know in Python or Ruby, but in Perl you can easyly use this feature with Net::OpenSSH. For instance:

use Net::OpenSSH;
my $ssh = Net::OpenSSH->new($host);
my $out = $ssh->capture({tunnel => 1,
                         stdin_data => "GET / HTTP/1.0\n\n" },
                        'www.google.com', 80);

print $out;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top