Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically create ssh tunnel in C/C++ cross-platform?

I need to connect via TCP to a port that's behind a firewall, accessible through an SSH tunnel. I can achieve connection by opening a tunnel and hittting that port, but I want to build this tunneling in to my application.

Additionally, I want to be able to provide automatic login by use of having authorized keys on the server

This must work on the following platforms (in order of importance)

  • iOS (trickiest because I can't fork an ssh tunnel like I can on other platforms)
  • OS X
  • Linux
  • Windows

What's the easy way to do this? I don't want to spend a great deal of effort obviously since this isn't the meat of my application. But I'll reuse it so I may care enough to "do things right"

like image 261
Nektarios Avatar asked Feb 15 '11 18:02

Nektarios


People also ask

How do I tunnel over SSH?

Set up SSH Tunneling in WindowsLaunch Putty and enter the SSH server IP Address in the Host name (or IP address) field. Under the Connection menu, expand SSH and select Tunnels . Check the Local radio button to setup local, Remote for remote, and Dynamic for dynamic port forwarding.


Video Answer


1 Answers

But libssh2 is BSD-licensed and appears to have the functionality needed

Looks like: libssh2_channel_direct_tcpip_ex will be the call

Note that the LGPL'd libssh is a problem because on iOS apps you MUST statically link and CANNOT dynamically link to libraries. Therefore, using an LGPL'd library means my source becomes open source.

like image 99
Nektarios Avatar answered Oct 03 '22 07:10

Nektarios