用法:
sshpass 參數SSH命令(ssh,sftp,scp等)。
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
比如說:
[email protected]:/home/xxx/test/root 這個命令的作用是將服務器端文件test傳到本地文件夾/root下。
利用sshpass,假設密碼爲efghi,則可寫作:
ssh -p efghiscp [email protected]:/home/xxx/test /root
另外,對於ssh的第一次登陸,會提示:“Are you sure you want to continue connecting(yes/no)”,這時用sshpass會不好使,可以在ssh命令後面加上 -oStrictHostKeyChecking=no來解決。比如說上面的命令,就可以寫作ssh -p efghi [email protected]:/home/xxx/test /root -oStrictHostKeyChecking=no。