HowTo: Execute A Script On Remote UNIX / Linux Server

by on May 27, 2009 · 9 comments· LAST UPDATED November 22, 2013

in , ,

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.
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Estimated completion timeN/A

ssh command line syntax

The basic syntax is as follows:

ssh user@server-name-here /path/to/script
ssh user@server-name-here /path/to/script arg1 arg2 arg3


ssh user@server-name-here /path/to/command
ssh user@server-name-here /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/

You can pass command line arguments too:

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

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

ssh date

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

ssh /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.

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 9 comments… read them below or add one }

1 Yong Cao June 21, 2010 at 4:17 pm

This is very good and helpful stuff.
Thanks a lot
Yong Cao


2 jay P March 2, 2012 at 4:49 am

How can I add Password to this “ssh date”


3 webskein March 11, 2012 at 4:43 pm

jay – you could try “passwordless ssh”. There’s stuff on Google about that.


4 Murryy December 11, 2012 at 7:19 pm

will this work if the script on the remote is interative ? If not can anyone give more suggestions.
Thank you


5 kavin June 10, 2013 at 6:51 am

Thanks working fine


6 M.C. Swart November 22, 2013 at 1:08 pm

How to start this by a cronjob


7 Pranesh November 5, 2014 at 3:03 pm

How to run these below at the same time. (Parallelly). Is it possible?
by anyway is fine like (Perl/Python/shell)

ssh user@server1 /root/scripts/
ssh user@server2 /root/scripts/


8 Mahendra February 6, 2015 at 5:15 am

Put & at the end of the command as below. Ampersand will put the command in the background.
ssh user@server1 /root/scripts/ &
ssh user@server2 /root/scripts/ &


9 Abhishek I February 23, 2015 at 1:44 pm

Thank you.
This helped me.


Leave a Comment

Tagged as: , , , , , , , , , , ,

Previous Faq:

Next Faq: