linux scp自动填充密码脚本

在linux上使用scp命令传输文件时,每传输一次,都要填写目标服务器的登录密码,十分麻烦。
配置系统密钥又比较复杂,于是想到的使用expect写一个自动填充密码的脚本,脚本内容如下:
scp.sh

#!/usr/bin/expect
set timeout 30
set file [lindex $argv 0]

spawn scp $file root@xxx.xxx.xxx.xxx:目标服务器文件保存路径

expect -re "password:" { send "你的服务器密码\r" }
expect eof

使用:
./scp.sh [文件路径]

posted @ 2021-10-25 17:28  BrianSun  阅读(2479)  评论(0编辑  收藏  举报