且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用SSH在远程计算机上运行Shell脚本?

更新时间:2022-12-23 09:41:59

如果计算机A是Windows机器,则可以使用Plink(

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

如果计算机A是基于Unix的系统,则可以使用:

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.