authenticationautomationcommand-line-interfacelastpasspasswordvault

How to automate the Lastpass CLI login process


I was wondering if anyone successfully automated the LastPass CLI login process. I cannot seem to get around the password prompt, which I need to automate to make it useful.

I've tried commands like

echo <password> | lpass login <username>

or

yes <password> | lpass login <username>

I keep getting output saying the password is not correct. Has anyone automated this?

Thanks!


Solution

  • You would probably need to disable the pinetry password prompt so that lpass reads your password from standard input.

    As the man pages say:

    If pinentry program is unavailable, or if the LPASS_DISABLE_PINENTRY environment variable is set to 1, passwords will be read from standard input and a prompt will be displayed on standard error.

    Meaning: It should work if you run it like this:

    echo <password> | LPASS_DISABLE_PINENTRY=1 lpass login <username>
    

    Or by just setting the environment variable for your shell (export LPASS_DISABLE_PINENTRY=1 in your ~/.profile or similar)