Search code examples
linuxwindowsbashexecute

execute bash script from shared folder in windows explorer


I have a network with windows and Ubuntu linux machines on it. The linux machine has a shared folder that allows the windows machines to see the files in this folder. I would like to allow windows users to execute a bash script that is in the shared folder. 1. Is this possible? 2. If so, how do I make it happen?


Solution

  • AFAIK you cannot execute the scripts via your shared folders for security reasons. If you are using file sharing services such as NFS or Samba you probably aren't allowed to do that.

    The simplest way to execute bash scripts remotely from Windows is using a shortcut to PuTTY with the location of your script on the Windows machine and login credentials to the Linux box.

    Storing your password in plain text is not considered safe, as anyone who has physical access to the computer can retrieve your password trivially. Only do this if you know what you're doing. Omitting -pw yourPassword will require you to enter your password each time you run the script.

    The target of your shortcut will look something similar to this:

    C:\putty.exe [email protected] -pw yourPassword -m "C:\path\to\test.bash"
    

    PuTTY Shortcut

    Where test.bash is your bash script. Example:

    #!/usr/bin/env bash
    
    touch itWorked
    

    Result:

    [root@pivos-m3 ~]# ll itWorked
    -rwxr-xr-x    1 root     root           0 Sep 23 14:05 itWorked*
    

    Alternatively, you could probably write a Batch file script to execute the bash script over ssh, but PuTTY is a much simpler approach.