用sshpass實現ssh的自動登陸


要實現ssh自動登錄,網上搜了一下,主要有兩種方法:1、生成公鑰。2、編寫expect腳本。這兩種方法,還有一種是sshpass:
用法:

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。用sshpass實現ssh的自動登陸 - 努力加貝 - 努力加貝
發佈了36 篇原創文章 · 獲贊 13 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章