Sean Nguyen
Sean Nguyen

Reputation: 13128

execute code in remote linux machine

I need to execute shell script on my remote linux machine. Do you know any tools that can help me doing that?

Thanks,

Upvotes: 2

Views: 1544

Answers (4)

Piyush Baijal
Piyush Baijal

Reputation: 281

  1. If you want to execute a local script on remote host

ssh remotePassword@remoteHost < localScript.sh

  1. If you want to invoke a script on remote host

ssh remotePassword@remoteHost "remoteScript.sh"

Upvotes: 0

lfagundes
lfagundes

Reputation: 3068

You can connect through ssh passing a command as a parameter:

ssh [email protected] "~/myscript.sh"

To connect without password, use ssh keys. To use keys, you have to generate a pair at your machine, with the command:

ssh-keygen

Then take the contents of the file ~/.ssh/id_rsa.pub (or id_dsa.pub if you use parameter -t dsa in ssh-keygen) and put in the file ~/.ssh/authorized_keys of the remote_machine. The .ssh dir must have permission 700.

Upvotes: 3

Bradford
Bradford

Reputation: 4193

Passwordless remote execution without waiting for remote script to complete before terminating the ssh connection:

ssh -i ~/.ssh/id_rsa user@remote nohup sh /path/to/script.sh > /dev/null 2>&1 & 

Upvotes: 0

ismail
ismail

Reputation: 47602

For Python you can use Paramiko to run commands on the remote computer over SSH.

Upvotes: 1

Related Questions