我正在尝试将txt / log文件从server1移动到server2。
我正在尝试使用SFTP连接到服务器从server1到server2,但有些人在提示中要求输入密码。任何人都可以让我知道如何通过脚本输入密码并使用脚本执行此功能。 请尽快告诉我......
我的代码:
test.sh是脚本,1.txt文件有密码详细信息.....
代码:test.sh sftp mwctrl @ sacsun11< 1.txt<> out.log 2>& 1 cd / usr / ftadapters / logs / adapters / rivaadp lcd / export / home / eisape 把* .txt 出口 EOF
的1.txt: 密码m33tzn3
答案 0 :(得分:2)
实际上您需要将ssh密钥添加到远程计算机。查看以下文章:
答案 1 :(得分:0)
设置ssh密钥相对简单。按照上面fxzuz发布的链接中的说明进行 <1分钟。
但通常将密码作为参数传递/存储在配置文件中会被视为安全风险。
但是,如果您仍想继续,请点击此链接 - http://nixcraft.com/shell-scripting/4489-ssh-passing-unix-login-passwords-through-shell-scripts.html
答案 2 :(得分:0)
尝试使用此
/usr/bin/expect <<EOF
spawn sftp -oStrictHostKeyChecking=no -oCheckHostIP=no mwctrl@sacsun11 \
"cd /usr/ftadapters/logs/adapters/rivaadp \
lcd /export/home/eisape \
put *.txt \"
expect "*?assword:*"
send "m33tzn3"
send "\r"
set timeout -1
send "\r"
expect EOF