scp远程拷贝,不用输入密码的方法

在写bash时遇到一个问题,从远程scp文件到本地,需要输入密码,如何自动实现该过程?


#!/bin/bash
#file_name: expect_1.sh
src_host=192.168.1.103
src_pwd=tom@ether
src_path=/home/chi/server2.c
src_user=chi
expect -c "
spawn scp ${src_user}@${src_host}:${src_path}  .
expect \"password:\"
send \"${src_pwd}\r\"
expect eof
"

[chi@yitai01 ~]$ ./expect_1.sh 
spawn scp [email protected]:/home/chi/server2.c .
Address 192.168.1.103 maps to yitai02, but this does not map back to the address - POSSIBLE BREAKIN ATTEMPT!
[email protected]'s password: 
server2.c                                     100% 1969     1.9KB/s   00:00 

看到了吧,不用手工输入密码输入,jiu ke yi copy.


你可能感兴趣的:(scp远程拷贝,不用输入密码的方法)