Linux 带密钥+密码的lftp?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11577090/
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 13:52:06  来源:igfitidea点击:

lftp with key + passphrase?

linuxkeysftppassphraselftp

提问by Hakadel

I'm using lftpto send files to a sftp server, but i don't how to connect with key and passphrase.

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

So in sftp, I can do this :

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

sftp -i .ssh/id_rsa.mykey [email protected]
Enter passphrase for key '.ssh/id_rsa.mykey': my passphrase here

So, how can I using lftp with this connecting method ?

那么,如何通过这种连接方法使用 lftp 呢?

采纳答案by Beau Barker

You must specify the username, and just pass anything as the password, to skip it asking.

您必须指定用户名,并将任何内容作为密码传递,以跳过询问。

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

回答by Jean-Luc Boss

LFTP doesn't seem to pass or does not use the identity file specified with "ssl:key-file" with SSH, you have to specify it in the sftp:connect-program option: "ssh -a -x -i yourprivatekeyfile"

LFTP 似乎没有通过或不使用“ssl:key-file”指定的身份文件与 SSH,您必须在 sftp:connect-program 选项中指定它:“ssh -a -x -i yourprivatekeyfile”

This should work.

这应该有效。

回答by nwgat

Just add:

只需添加:

set sftp:connect-program "ssh -a -x -i yourprivatekeyfile"

to your ~/.lftprc, as most of the settings can be set permanently there.

到您的~/.lftprc,因为大多数设置都可以在那里永久设置。

回答by me_and

An answer based off Jean-Luc Boss's and wiak's, but a bit more explicit:

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

To connect to a server, lftpuses an sshcommand, by default ssh -a -x. It doesn't have an explicit option for changing the keyfile to use, but as you note, sshdoes, so we just need to set lftpto connect using ssh -a -x -i <keyfile>before it connects.

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

You can do this in a few ways:

您可以通过以下几种方式执行此操作:

  • 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 lftpusing -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://[email protected]; 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 ~/.lftprcfile (or one of the other configuration file options listed in man lftp).

  • 如果您使用的是 lftp 的交互式命令行,请在连接前运行以下命令:

    set sftp:connect-program "ssh -a -x -i <keyfile>"
    
  • 如果您要指定一堆命令lftpusing -c,只需将该 set 命令添加到您的命令序列的开头:

    lftp -c 'set sftp:connect-program "ssh -a -x -i <keyfile>"; connect sftp://[email protected]; mirror -eR files; ...'
    
  • 如果您总是想要使用相同的密钥,只需将set ...第一项中的那一行添加到您的~/.lftprc文件(或 中列出的其他配置文件选项之一man lftp)。