HowTo: Execute A Script On Remote UNIX / Linux Server

How do I execute a script on remote server called from my PC? How to run a shell/python/perl script on remote Unix-like systems?

You can use the ssh client which is a part of most *BSD/Linux/OS X/Linux distros/Unix-like oses. If you are on MS-Windows operating systems you need to download and use Putty client.[donotprint][/donotprint]

ssh command line syntax

The basic syntax is as follows:

ssh [email protected] /path/to/script
ssh [email protected] /path/to/script arg1 arg2 arg3


ssh [email protected] /path/to/command
ssh [email protected] /path/to/command arg1 arg2


Open the Terminal. To run a script called /root/scripts/ on remote UNIX or Linux server called, enter:

ssh /root/scripts/

ssh [email protected] /root/scripts/

You can pass command line arguments too:

ssh /scripts/job.init --job=sync --type=aws --force=true

ssh [email protected] /scripts/job.init –job=sync –type=aws –force=true

You can execute the date command as follows on remote server:

ssh date

ssh [email protected] date

You may need to specify full script path. In this example, run /root/ script as follows:

ssh /root/

ssh [email protected] /root/

To avoid password prompt set password less ssh keys or use tool such as keychain – a manager for ssh-agent, typically run from ~/.bash_profile.

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.