標籤:linux scp sshpass expect
1.通過sshpass讓ssh記住密碼實現ssh自動登陸(1)安裝sshpasssudo apt-get install sshpass或者下載sshpass-1.05.tar.gzshell>tar xvf sshpass-1.05.tar.gzshell>cd sshpass-1.05shell>make && make install(2)測試shell>/usr/local/bin/sshpass -p 密碼 ssh [email protected](3)設定避免公開金鑰確認ssh在首次連結時會提示公開金鑰確定,這會導致某些自動化任務失敗shell>sudo vim /etc/ssh/ssh_config##添加下面一句StrictHostKeyChecking no(4)把原生~/examples.desktop傳到192.168.1.1的~目錄下sshpass -p 123456 scp ~/examples.desktop [email protected]:~2.通過expect傳輸檔案(1)安裝expectsudo apt-get install expect(2)測試把192.168.1.1的/home/test/soft.tar傳輸到原生/home/test#!/usr/bin/expect -f#filename: scp_expect.shset password 123456spawn scp -r [email protected]:/home/test/soft.tar /home/testset timeout 3expect {"yes/no" {send "yes\r";exp_continue}}set timeout 3send "$password\r"##傳輸需要的時間set timeout 300send "exit\r"expect eof
本文出自 “筆記” 部落格,請務必保留此出處http://sunflower2.blog.51cto.com/8837503/1554419
shell---scp遠程傳輸檔案不需要手動輸入密碼