lftp如何使用密钥和密码短语?

13

我正在使用lftp将文件发送到SFTP服务器,但我不知道如何使用密钥和密码短语进行连接。

所以在sftp中,我可以这样做:

sftp -i .ssh/id_rsa.mykey login@my.host.fr
Enter passphrase for key '.ssh/id_rsa.mykey': my passphrase here

那么,我该如何使用lftp进行这种连接方法?

我也尝试过:

lftp -e "set ssl:key-file .ssh/id_rsa.mykey" sftp://my.host.fr
4个回答

24

基于Jean-Luc Boss和wiak的答案,但更加明确:

要连接到服务器,lftp使用一个ssh命令,默认为ssh -a -x。它没有显式选项来更改要使用的密钥文件,但正如您所指出的那样,ssh有这个选项,因此我们只需要在连接之前设置lftp以使用ssh -a -x -i <keyfile>进行连接。

您可以通过以下几种方式实现:

  • If you're using lftp's interactive command line, run the following command before you connect:

    set sftp:connect-program "ssh -a -x -i <keyfile>"
    
  • If you're specifying a bunch of commands to lftp using -c, just add that set command to the start of your command sequence:

    lftp -c 'set sftp:connect-program "ssh -a -x -i <keyfile>"; connect sftp://user@example.com; mirror -eR files; ...'
    
  • If you always going to want to use the same key, just add that set ... line from the first bullet to your ~/.lftprc file (or one of the other configuration file options listed in man lftp).


您必须拥有一个可以通过SSH连接的用户。 - MUY Belgium

18

你必须指定用户名,只需将任何内容作为密码传递,以跳过它要求密码的步骤。

lftp -u user,xxx sftp://...

13
lftp -u user, sftp://hostname 这条命令也可以生效(注意逗号的存在)。 - Felipe Alvarez
1
由于某些原因,如果您需要发送私钥和密码,则此方法无法正常工作。密码未被发送或未被正确发送。 - The Lizard

8
只需要添加以下代码:
set sftp:connect-program "ssh -a -x -i yourprivatekeyfile"

将设置添加到您的~/.lftprc中,因为大部分设置可以在那里永久设置。


2

LFTP似乎没有传递或者没有使用通过"ssl:key-file"指定的身份文件。你需要在sftp:connect-program选项中指定它:

ssh -a -x -i yourprivatekeyfile

这应该可以工作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接