天天看點

sshpass: 用于非互動的ssh 密碼驗證

sshpass: 用于非互動的ssh 密碼驗證

ssh登陸不能在指令行中指定密碼,也不能以shell中随處可見的,sshpass 的出現,解決了這一問題。它允許你用 -p 參數指定明文密碼,然後直接登入遠端伺服器。 它支援密碼從指令行,檔案,環境變量中讀取

$> 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

   -h Show help (this screen)

   -V Print version information

At most one of -f, -d, -p or -e should be used

sshpass [-f|-d|-p|-e] [-hV] command parameters 中的 command parameters 和使用互動式密碼驗證的使用方法相同

#從指令行方式傳遞密碼

    $> sshpass -p user_password ssh [email protected]

    $> sshpass -p user_password scp -P22 192.168.1.2:/home/test/t . 

#從檔案讀取密碼

    $> echo "user_password" > user.passwd

    $> sshpass -f user.passwd ssh [email protected]

#從環境變量擷取密碼

    $> export SSHPASS="user_password"

    $> sshpass -e ssh [email protected] 

源碼位置:http://sourceforge.net/projects/sshpass/

--------------end--------------

From: GS

-------------------------------

CentOS6安裝sshpass:

cd /etc/yum.repos.d/
wget http://download.opensuse.org/repositories/home:Strahlex/CentOS_CentOS-6/home:Strahle.repo
yum install sshpass      

繼續閱讀