I want to login to a remote system in ubuntu using a script file which will be executed in my system . The script contains the following commands
#!/bin/bash
echo 'systemPwd' | ssh myMachine@192.168.0.59
By executing this script I could not log in to the system. It doesn't gets the password from the echo command. But I don't know how to use alternatives.
But I tried this script
#!/bin/bash
sshpass -p 'systemPwd' ssh myMachine@192.168.0.58 <<-'ENDSSH'
#commands to run on remote host
echo 'systemPwd' | sudo -S shutdown-h now
ENDSSH
In the above script the sshpass
has been used. The problem is that sshpass
has to be installed first. Anyone suggest an alternative method for this which would make me to connect to remote system without sshpass
.
ssh-keygen
on a different machine; all it does is to generate a pair of keys: one for the client and one for the server. – Chris Davies Jan 30 '17 at 10:28