in reply to Problem executing command via ssh

As haukex mentioned, you probably should be using a module for the SSH connection. Two recent questions suggest that Net::SSH::Perl might be useful and give both some pitfalls and solutions.

Further, the SSH configuration you describe does not do what you seem to think that it does — the user account that you have created can get a shell with "ssh user@remotehost.com /bin/sh". You need to use the "forced command" option with the public key registered on the remote machine to ensure that that key can only be used to run your program, and you really need to read perlsec if that remote program is written in Perl and make sure that it cannot be abused to gain a shell if you do not want shell access to be available.

Lastly, one big difference between running ssh on a terminal and on pipes is whether SSH sets up a pty on the remote machine by default. Try "ssh -tt user@remotehost.com" instead if you insist on using IPC::Open3 for this.

Replies are listed 'Best First'.
Re^2: Problem executing command via ssh
by haukex (Archbishop) on Aug 24, 2019 at 06:53 UTC
    Two recent questions suggest that Net::SSH::Perl might be useful

    On Windows maybe, but on *NIX systems, IMHO Net::OpenSSH is really the best, it supports a ton of functionality and builds on the native ssh. No messing around with IPC::Open3 necessary :-)

Re^2: Problem executing command via ssh
by mgalindez (Initiate) on Aug 25, 2019 at 13:54 UTC
    Doing: ssh user@remotehost.com /bin/sh does not get me /bin/sh, but the default shell for the corresponding user. Am I missing something? Thanks!

      It is possible that /bin/sh may be a special case in newer versions of the SSH server or you have some other configuration acting as a "safety net" in your case. I still would not recommend depending on this; you should be using the "forced command" option on the public key to ensure that it can only be used to run your program and you still need to read perlsec and make sure that your program cannot be exploited into a shell-equivalent if this is an actual security issue.