简体   繁体   English

使用密钥和密码自动进行SFTP登录

[英]Automate SFTP login using both key and password

Recently SFTP hosted servers are enabled with two factor authentication. 最近,SFTP托管服务器已启用两因素身份验证。 For details please refer the link here. 有关详细信息,请单击此处的链接

Now, we have requirement to automate this setup using command line. 现在,我们需要使用命令行自动执行此设置。 I found that as two different options for doing this: 我发现这样做有两个不同的选择:

 sshpass -p password sftp -oBatchMode=no -oStrictHostKeyChecking=no username@server1

 sftp -oIdentityFile=/path/to/private/key/file -oBatchMode=no -oStrictHostKeyChecking=no username@server1

But now I need to combine these two into single command and use it in my script for automating this sftp flow. 但是现在我需要将这两个合并为单个命令,并在我的脚本中使用它来自动执行此sftp流。

So, at first I need to send the private key file in the command line and then send the password in the same command line. 因此,首先我需要在命令行中发送私钥文件,然后在同一命令行中发送密码。 I tried few options but it didn't work. 我尝试了几种选择,但是没有用。

How hard can it be to put both lines together: 将这两条线放在一起有多难:

sshpass -p password sftp -oBatchMode=no -oStrictHostKeyChecking=no \
  -oIdentityFile=/path/to/private/key/file username@server1

ssh itself will take care of both authentication methods. ssh本身将同时使用两种身份验证方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM