lftp with key + passphrase

Hakadel picture Hakadel · Jul 20, 2012 · Viewed 32.5k times · Source

I'm using lftp to send files to an SFTP server, but I don't how to connect with key and passphrase.

So in sftp, I can do this:

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

So, how can I use lftp with this connection method?

Answer

me_and picture me_and · Sep 4, 2014

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

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

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 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://[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 ~/.lftprc file (or one of the other configuration file options listed in man lftp).