How to use SSH to run a local shell script on a remote machine?

前端 未结 17 1563
南笙
南笙 2020-11-21 22:33

I have to run a local shell script (windows/Linux) on a remote machine.

I have SSH configured on both machine A and B. My script is on machine A which will run some o

17条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-21 23:02

    If Machine A is a Windows box, you can use Plink (part of PuTTY) with the -m parameter, and it will execute the local script on the remote server.

    plink root@MachineB -m local_script.sh
    

    If Machine A is a Unix-based system, you can use:

    ssh root@MachineB 'bash -s' < local_script.sh
    

    You shouldn't have to copy the script to the remote server to run it.

提交回复
热议问题