[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ssh connection via a proxy


On 03/08/2021 09:44, Andreas Schneider wrote:
> On Tuesday, August 3, 2021 9:16:15 AM CEST Jeremy Fix wrote:
>> On 03/08/2021 08:52, Andreas Schneider wrote:
>>> On Monday, August 2, 2021 11:28:10 PM CEST Jeremy Fix wrote:
>>>> Hello,
>>> Hi,
>>>
>>>> I would like to use libssh for connecting to a remote host via a
>>>> gateway, executing a command on the remote host and parsing its standard
>>>> outputs/errors; So the picture is  localhost -> gateway -> remote
>>>>
>>>> I'm pretty new with libssh. I used to do that with command line ssh by
>>>> specifying
>>>>
>>>>     ssh -o ProxyCommand='ssh -W %h:%p mylogin@gateway' mylogin@remote
>>>>
>>>> mycommand
>>>>
>>>> It is not obvious to me how to do that with libssh; One track I have in
>>>>
>>>> mind is a variant of the above with :
>>>>     ssh -L 9999:remote:22 mylogin@gateway
>>>>     
>>>>     ssh -p 9999 mylogin@localhost mycommand
>>>>
>>>> therefore I would establish a tunnel then create a new libssh session on
>>>> localhost and execute the command in a channel on this new session.
>>> Which part to do you want to implement with libssh exactly. The client
>>> side or the proxy or both?
>> I think I need to implement the whole chain. To specify the constraints;
>> I need my program to run on Linux/Windows/MacOS and I thought, but I may
>> be wrong, that I need to handle everything related to ssh with libssh.
>>
>>> libssh supports the proxy command see the options:
>>> https://api.libssh.org/stable/
>>> group__libssh__session.html#ga7a801b85800baa3f4e16f5b47db0a73d
>>>
>>> SSH_OPTIONS_PROXYCOMMAND: Set the command to be executed in order to
>>> connect to server (const char *).
>> I agree but what puzzles me is that my proxy command "ProxyCommand='ssh
>> -W %h:%p mylogin@gateway'" does involve ssh which I should also handle
>> with libssh I believe.  If I want my program to be cross platform,
>> shouldn't I also code the  'ssh -W %h:%p mylogin@gateway' with libssh ? 
> You don't need a proxy command if you implement the proxy yourself ...
>
> https://git.libssh.org/projects/libssh.git/tree/examples/proxy.c
>
>
Ok, I will give a try to that code, running and dissecting it. I must
admit that a quick glance other it is not sufficient for me to
understand it;

From my understanding of a proxy, I naively thought that setting up a
proxy would require a ssh_session for it, and then a call to
ssh_channel_open_forward while the proxy.c file does involve a ssh_bind
and ssh_event. Could you tell me the reason why these two structures are
required ?



References:
ssh connection via a proxyJeremy Fix <Jeremy.Fix@xxxxxxxxxxxxxxxxxx>
Re: ssh connection via a proxyAndreas Schneider <asn@xxxxxxxxxxxxxx>
Re: ssh connection via a proxyJeremy Fix <Jeremy.Fix@xxxxxxxxxxxxxxxxxx>
Re: ssh connection via a proxyAndreas Schneider <asn@xxxxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org