方法一:基于公钥和私钥的信任办法
ssh-keygen -t rsa
1、在服务器A、B中分别生成ssh-key,生成方式输入ssh-keygen,然后连续回车
2、进入.ssh目录,拷贝服务器B中的id_rsa.pub文件内容
3、在服务器A目录.ssh下面新建文件authorized_keys,把服务器B中的id_rsa.pub文件内容复制进去
后续使用SCP命令远程拷贝文件B->A,不再需要输入密码
方法二:sshpass
sshpass的安装:
Ubuntu:apt-get install sshpass
centos:
下载地址:http://sourceforge.net/projects/sshpass/
wget http://sourceforge.net/projects/sshpass/files/sshpass/1.05/sshpass-1.05.tar.gz
yum -y install gcc
tar xvzf sshpass-1.05.tar.gz
cd sshpass-1.05.tar.gz
./configure
make
make install
sshpass -p 密码 scp -r 1.txt [email protected]:/root
sshpass -f 存放密码的文件 scp -r 1.txt [email protected]:/root