Linux 没有密码提示的 SFTP 连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11880639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:02:36  来源:igfitidea点击:

SFTP Connection with out password prompt

linuxunix

提问by user1227648

I am trying to move txt/ log file from server1 to server2.

我正在尝试将 txt/ 日志文件从 server1 移动到 server2。

I am trying to connect to a server from server1 to server2 using SFTP but some how it is asking for password in the prompt.Can anyone let me know how to give password as input through script and execute this functionality using a Script. Please let me know asap......

我正在尝试使用 SFTP 连接到从 server1 到 server2 的服务器,但它是如何在提示中要求输入密码的。谁能告诉我如何通过脚本提供密码作为输入并使用脚本执行此功能。请尽快告诉我......

MY CODE:

我的代码:

test.sh is script and 1.txt file has password details.....

test.sh 是脚本,1.txt 文件有密码详细信息.....

code: test.sh sftp mwctrl@sacsun11 < 1.txt <> out.log 2>&1 cd /usr/ftadapters/logs/adapters/rivaadp lcd /export/home/eisape put *.txt exit EOF

代码:test.sh sftp mwctrl@sacsun11 < 1.txt <> out.log 2>&1 cd /usr/ftadapters/logs/adapters/rivaadp lcd /export/home/eisape put *.txt exit EOF

1.txt: password m33tzn3

1.txt:密码m33tzn3

回答by Pavel Vlasov

Actually you need add ssh keys to remote machine. Check article below:

实际上您需要将 ssh 密钥添加到远程机器。检查下面的文章:

Using sftp without password (http://says-story.blogspot.nl/2008/01/using-ssh-scp-sftp-without-password.html)

使用没有密码的 sftp (http://says-story.blogspot.nl/2008/01/using-ssh-scp-sftp-without-password.html)

回答by dopplesoldner

Setting up ssh keys is relatively simple. Takes <1 minfollowing the instructions in the link posted above by fxzuz.

设置 ssh 密钥相对简单。取<1分钟以上发表fxzuz以下中的链接的说明。

But generally passing passwords as parameters / storing in config files is considered a security risk.

但通常将密码作为参数传递/存储在配置文件中被认为是一种安全风险。

However, if you still want to go ahead, here is a link -- http://nixcraft.com/shell-scripting/4489-ssh-passing-unix-login-passwords-through-shell-scripts.html

但是,如果您仍然想继续,这里有一个链接——http://nixcraft.com/shell-scripting/4489-ssh-passing-unix-login-passwords-through-shell-scripts.html

回答by user1011046

try using this

尝试使用这个

/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