Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Net::OpenSSH mater mode is not working

by leostereo (Beadle)
on Sep 30, 2020 at 14:02 UTC ( #11122369=perlquestion: print w/replies, xml ) Need Help??

leostereo has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys.

Im using Net::OpenSSH to connect multiple times to same host , exec some commands and grab it output.

Problem is that I can not make module to work with master mode.

I have read the documentation but can not get it to work.

This is how Im creating object:

my $ssh = Net::OpenSSH->new( $source, $login ? ( user => $login ) : (), $password ? ( password => $password ) : (), #external_master => 1, port => $port, timeout => 60, strict_mode => 0, kill_ssh_on_timeout => 1, ctl_dir => "/tmp/.libnet-openssh-perl", #ctl_path => "reusable_path", master_opts => [-o => "StrictHostKeyChecking=no"], ssh_cmd => $ssh_cmd );

If uncommenting external_master line I get Invalid or bad combination of options ('master_opts')

If uncommenting ctrl_path, I get "ControlSocket reusable_path already exists, disabling multiplexing",

Dont know what to try ... I thought module needs to find existing path so it can reuse but no.

Any help wouls be wellcome.

Leandro

Replies are listed 'Best First'.
Re: Net::OpenSSH mater mode is not working
by salva (Canon) on Sep 30, 2020 at 16:28 UTC
    You have to remove the master_opts line. You are telling the module you are using an already existent master process, so it doesn't accept options telling it how to create a new one.

    In any case, using an external master is not very common. Are you sure it is really what you want?

      Ok , I will try to clear my goal.
      If I append:

      Host * controlmaster auto controlpath /tmp/ssh-%r@%h:%p

      to ssh_config file,
      Then I can: ssh host@ip:port to my server multiple times , and from the server side, I will only see only one active connection (the first one).
      I would like to achieve samething using OpenSSH perl module.
      What I can see is that openssh module creates random sockets , so it will never reuse an existing one (please add your opinion here)
      like:

      [root@smokeping probes]# ls -altr /tmp/.libnet-openssh-perl/ total 8 drwxrwxrwt. 12 root root 4096 Oct 1 10:02 .. srw-------. 1 root root 0 Oct 1 10:02 77920c754112ab47c6163bcfc58 +bed18 srw-------. 1 root root 0 Oct 1 10:02 0c600465ef924c5229c418a8871 +b9d36 srw-------. 1 root root 0 Oct 1 10:02 e675b23529a57eb7b59e85a7237 +7df74 srw-------. 1 root root 0 Oct 1 10:02 e4690abec752975a4476dd63232 +19814 srw-------. 1 root root 0 Oct 1 10:02 d3e28b44e996a2c3858850156cc +3b238 srw-------. 1 root root 0 Oct 1 10:02 24c7eb01f6b8e230db4e7ad7464 +6cc54 srw-------. 1 root root 0 Oct 1 10:02 8146e02629748a287f979c16827 +6b114 srw-------. 1 root root 0 Oct 1 10:02 6a7ebf7458398a282a947479de0 +14edc srw-------. 1 root root 0 Oct 1 10:02 6c1ebc546764c1bfbd755d1820d +bf5a5 srw-------. 1 root root 0 Oct 1 10:02 67d4449c8336035d4bc66fccf47 +ceddf srw-------. 1 root root 0 Oct 1 10:02 af933a70fa19f2e0631dd381587 +d9797 srw-------. 1 root root 0 Oct 1 10:02 09653a62f88e4954a6ba2c85a74 +37400 srw-------. 1 root root 0 Oct 1 10:02 b8b2ecc3c59c9bd14a147b0f4e4 +ebb01 srw-------. 1 root root 0 Oct 1 10:02 c9eb9ff5c25c1ea8bf8ae6fa0a9 +e6550 srw-------. 1 root root 0 Oct 1 10:02 966185842d9ab1ff5ce17afd3c9 +51893 srw-------. 1 root root 0 Oct 1 10:02 cf32ef2944cab6c8aeb5055b1a6 +72ee3 srw-------. 1 root root 0 Oct 1 10:02 a6c87213c639efca7be3d902b97 +f14ca srw-------. 1 root root 0 Oct 1 10:02 7c903101f2588c0d59ba1951806 +ab423 srw-------. 1 root root 0 Oct 1 10:02 0d8fe313c0fe25601df92bd10f5 +5f48a srw-------. 1 root root 0 Oct 1 10:02 5073e76ae24b05de392b4b12577 +7138e srw-------. 1 root root 0 Oct 1 10:02 a3c0acb9d2765801610a1c80c88 +e8086

      So ... I dont know whow to tweak it to work as I want.
      Should I force openssh module to create allways same socket and then add the propper rule to ssh_config system file ?
      or both , perl module and ssh system client does nothing to do between them ?
      Ok , hope to be more clear about my task.
      Thanks.

        Net::OpenSSH does not support the mode of operation where the master is reused if available or otherwise, a new one is created.

        The reason is that doing it in a reliable way is pretty hard, there are lots of race conditions and edge cases that should be handled. On the other hand it is something I had never found too useful.

Re: Net::OpenSSH mater mode is not working
by perlfan (Vicar) on Sep 30, 2020 at 18:25 UTC
    You can further simplify this by utilizing a local ssh config, man 5 ssh_config, namely the master_opts => [-o => "StrictHostKeyChecking=no"] line. It certainly depends on the environment and control of the remote host, but you can also likely eliminate $login ? ( user => $login ) : (), $password ? ( password => $password ) : (), and port => $port, by leveraging the ssh config.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11122369]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2022-05-28 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (99 votes). Check out past polls.

    Notices?