1.通过sshpass让ssh记住密码实现ssh自动登陆 (1)安装sshpass sudo apt-get install sshpass 或者 下载sshpass-1.05.tar.gz shell>tar xvf sshpass-1.05.tar.gz shell>cd sshpass-1.05 shell>make && make install (2)测试 shell>/usr/local/bin/sshpass -p 密码 ssh root@127.0.0.1 (3)设置避免公钥确认 ssh在首次链接时会提示公钥确定,这会导致某些自动化任务失败 shell>sudo vim /etc/ssh/ssh_config ##添加下面一句 StrictHostKeyChecking no (4)把本机的~/examples.desktop传到192.168.1.1的~目录下 sshpass -p 123456 scp ~/examples.desktop root@192.168.1.1:~ 2.通过expect传输文件 (1)安装expect sudo apt-get install expect (2)测试 把192.168.1.1的/home/test/soft.tar传输到本机的/home/test #!/usr/bin/expect -f #filename: scp_expect.sh set password 123456 spawn scp -r test@192.168.1.1:/home/test/soft.tar /home/test set timeout 3 expect { "yes/no" {send "yes\r";exp_continue} } set timeout 3 send "$password\r" ##传输需要的时间 set timeout 300 send "exit\r" expect eof
本文出自 “笔记” 博客,请务必保留此出处http://sunflower2.blog.51cto.com/8837503/1554419
原文地址:http://sunflower2.blog.51cto.com/8837503/1554419