sshpass

2019-02-21  本文已影响0人  yc_he

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.

sudo apt-get install sshpass
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
#!/bin/bash
ssh user@remoteNode > /dev/null 2>&1 << eeooff
cd /home
touch abcdefg.txt
exit
eeooff
echo done!

Ref

上一篇下一篇

猜你喜欢

热点阅读