How To Run Shell Script or Command On Remote With SSH

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/run-shell-script-command-remote-ssh/
PINTEREST
PINTEREST
INSTAGRAM

I want to run my commands securely. Are there anyway for this? Yes there are a lot of options. But the most simple and secure way is running scripts or commands over ssh.

Run Command On Remote System

SSH is very powerful tool which can invoke provided commands on remote system or server. We will provide the command and options in a double quote. This command will run current users default shell which is generally bash. In this example we will run command on remote IP address 192.168.142.144 and user will be  ismail

Run Command On Remote System
Run Command On Remote System

Enable Key Based or Passwordless Remote Command Execution

As we can see that in order to run command on remote system we provided password for the given user. This can be prevent automated running or trivial task if we are running remote commands regularly. We can setup key based authentication which will do not ask further command execution. We will use ssh-copy-id to the remote system we wan to run command. For more details:

How To Login To Linux with Passwordless via SSH with Key Based Authentication?

Enable Key Based or Passwordless Remote Command Execution
Enable Key Based or Passwordless Remote Command Execution

Run Script On Remote System

Bash shell provides some PATH to find provided command in the binaries. If we want to run a script we need to provide the whole path of this script and run on bash shell properly. In this example we will provide a script which is located at /home/ismail/backup.sh on remote IP address 192.168.142.144 .

Run Local Script On Remote System

There is a problem what will be happen if the script is located in local system. Should we copy it to remote system and then run. May be it is solution but more convenient and easy way is echoing script to the remote bash session

LEARN MORE  How To Change OpenSSH SSH Server Port Number In Linux?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/run-shell-script-command-remote-ssh/
PINTEREST
PINTEREST
INSTAGRAM