There are several ways to execute a script on a remote Unix/Linux server. Here are a few options:
ssh
to log in to the remote server and run the script directly:ssh user@remote-server 'bash -s' < local-script.sh
This will log you in to the remote server as the user
user and run the local-script.sh
script on the remote server.
scp
to copy the script to the remote server, and then use ssh
to log in and run the script:scp local-script.sh user@remote-server:~/ ssh user@remote-server 'bash ~/local-script.sh'
This will copy the local-script.sh
script to the home directory of the user
user on the remote server, and then log you in to the remote server and run the script.
rsync
to copy the script to the remote server, and then use ssh
to log in and run the script:rsync local-script.sh user@remote-server:~/ ssh user@remote-server 'bash ~/local-script.sh'
This is similar to the previous method, but rsync
has the advantage of only transferring the parts of the file that have changed, which can be faster if the script is large.
Keep in mind that you will need to have the correct permissions and access to the remote server in order to execute the script.