Run a script or program on a remote server from a local server

Let’s say you want to run a program on one server from another server. First you need to install openssh on both machines. Note: for the remainder of this document I’m going to refer the serfer you want to send the command from as the local machine with user localusername and I’m going to call the server you want to run the program on the remote machine with user remoteusername.

To begin, open a terminal on the remote machine and:

sudo su

apt-get install openssh-server

Then log in to the local machine and repeat to install openssh there. Next we need to generate a public and private key on the local machine to permit logging in to the remote machine without a password. The command is:


when it asks for a password hit enter. The keys will be stored in ~/.ssh/id-rsa and ~/.ssh/

All that remains is to copy the public key from the local machine to the proper location on the remote machine. Accomplish that with:

cat /localusername/.ssh/ | ssh:remoteusername@WW:XX:YY:ZZ 'cat >> /home/remoteusername/.ssh/authorized_keys'

where WW:XX:YY:ZZ is the ipaddress of the remote machine.

You can then run the command on the remote machine with

ssh remoteusername@WW:XX:YY:ZZ ./scriptname

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: