如何运行与bash脚本密码SFTP命令? [英] How to run the sftp command with a password from Bash script?
问题描述
我需要一个日志文件传输到使用 SFTP 从Linux主机远程主机。我已经从我的行动小组提供相同的凭据。然而,由于我没有对其他主机的控制,我无法生成,并与其他主机共享的RSA密钥。
I need to transfer a log file to a remote host using sftp from a Linux host. I have been provided credentials for the same from my operations group. However, since I don't have control over other host, I cannot generate and share RSA keys with the other host.
那么,有没有办法通过的 SFTP 命令(提供的用户名/密码):// en.wikipedia.org/wiki/Cron\">cron 工作?
So is there a way to run the sftp
command (with the username/password provided) from inside the Bash script through a cron job?
我发现了一个类似的堆栈溢出问题的 指定密码的Bash脚本为sftp 的,但没有满意的回答我的问题。
I found a similar Stack Overflow question, Specify password to sftp in a Bash script, but there was no satisfactory answer to my problem.
推荐答案
您不是使用公共密钥认证等几个选项:
You have a few options other than using public key authentication:
- Use keychain
- Use sshpass (less secured but probably that meets your requirement)
- Use expect (least secured and more coding needed)
如果你决定给sshpass这里机会工作脚本片段这样做的:
If you decide to give sshpass a chance here is a working script snippet to do so:
export SSHPASS=your-password-here
sshpass -e sftp -oBatchMode=no -b - sftp-user@remote-host << !
cd incoming
put your-log-file.log
bye
!
这篇关于如何运行与bash脚本密码SFTP命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!