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/id_rsa.pub.
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/id_rsa.pub | 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