Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Pass local bash script to remote host via SSH

by perlfan (Vicar)
on Jun 24, 2020 at 11:48 UTC ( #11118414=note: print w/replies, xml ) Need Help??

in reply to Pass local bash script to remote host via SSH

My recommendation is also to use something like Net::OpenSSH as mentioned by my fellow Monks, but coupled with $HOME/.ssh/config so that you remove the need to manage (most if not all) ssh options inside of your script. So <remotehost> becomes <ssh_config_alias> in your DWIW illustration above.

In addition to this, there is nothing wrong with uploading a script file directly into $HOME/tmp then executing that script. In many ways this is much more clear and will be more easily understood by your future self during any maintenance of this program.

Finally be sure to protect the script appropriately, for example I would not blindly upload it to /tmp and I would ensure that only the remote system $USER is able to read the script. Also, clean up after by deleting the script.

For additional security, you may pass sensitive values to the script via the environment using the equivalent of ssh -o SendEnv=MYVAR directly or in your code. Any passwords or other secrets may be provided to the script this way and the script would just make use of them assuming they are defined. Do not send them to the script via commandline argument or by explicitly setting the value in the ssh command itself.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11118414]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2022-01-20 22:32 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (57 votes). Check out past polls.