How to run a local script on the remote host -- sshpass
Jing, mqjing@gmail.com
Googledoc
Security Issue
- Your password shows in the script.
This is an ugly method
Script file version
command
username=jing
ip=192.168.33.10
# Step 1: copy your local file to the remote site
# Note: Option StrictHostKeyChecking=no is mandatory otherwise the file will not be copy.
sshpass -p 1234 scp -o StrictHostKeyChecking=no "Your_Local_Script.sh" $username@$ip:~
# Step 2: run the script on the remote site
sshpass -p 1234 ssh -o StrictHostKeyChecking=no -t $username@$ip ". ./Your_Local_Script.sh"
|
Ex:
#!/bin/bash
ip=192.168.33.10
ssh-keygen -f ~/.ssh/known_hosts -R $ip
sudo apt-get -y --force-yes install sshpass
username=jing
ip=192.168.33.10
sshpass -p 1234 scp common_fun.sh $username@$ip:~
sshpass -p 1234 ssh -o StrictHostKeyChecking=no -t $username@$ip ". ./common_fun.sh; fun_setup_locale"
|
Command version
sshpass -p 1234 ssh -o StrictHostKeyChecking=no -t stack@$ip "echo nameserver 8.8.8.8 | sudo tee /etc/resolv.conf"
|