1. Install sshpass
SSHPass is a tiny utility, which allows you to provide the ssh password without using the prompt. This will very helpful for scripting. SSHPass is not good to use in multi-user environment. If you use SSHPass on your development machine, it don't do anything evil.
-
Installing on Linux
sudo apt-get install sshpass
-
Installing on Mac
Download the source code [https://sourceforge.net/projects/sshpass/]
tar xzvf sshpass-1.06.tar.gz
cd sshpass-1.06
./configure
sudo make install
2. Usage
ycdeMacBook-Pro:sshpass-1.06 yche$ sshpass -h
Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
-f filename Take password to use from file
-d number Use number as file descriptor for getting password
-p password Provide password as argument (security unwise)
-e Password is passed as env-var "SSHPASS"
With no parameters - password will be taken from stdin
-P prompt Which string should sshpass search for to detect a password prompt
-v Be verbose about what you're doing
-h Show help (this screen)
-V Print version information
At most one of -f, -d, -p or -e should be used
- Multiple commands in sshpass
#!/bin/bash
ssh user@remoteNode > /dev/null 2>&1 << eeooff
cd /home
touch abcdefg.txt
exit
eeooff
echo done!