How to execute a script on remote server by ssh command


From this tutorial you would learn how to execute a local script on remote server by ssh command.


  • Linux/Mac OS

The script

we write a script in current directory,which just prints the version info of the OS.

➜  ~ cat
uname -a

Execute it on remote server

ssh [email protected] 'bash -s' < ./
Linux server1 2.6-el6.x86_64 #1 SMP Thu Jul 30 17:20:51 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux


The key command is ssh [email protected] ‘bash -s’ < ./

You can find detail documents about the linux and ssh here: