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 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)安装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 test@192.168.1.1:/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