sshpass

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
Screen Shot 2019-02-21 at 10.06.41 AM.png
  • Multiple commands in sshpass
#!/bin/bash
ssh user@remoteNode > /dev/null 2>&1 << eeooff
cd /home
touch abcdefg.txt
exit
eeooff
echo done!

Ref

  • Installing SSHPass
  • mac使用sshpass连接ssh全教程
  • sshpass: An Excellent Tool for Non-Interactive SSH Login – Never Use on Production Server
  • Linux下使用SSH远程执行命令方法收集

你可能感兴趣的:(sshpass)