Setup
Install LastPass CLI
Log In
Verify Setup
Check thatlpass is working:
Template Functions
lastpass
Get structured data from a LastPass entry:
lpass show --json id.
lastpassRaw
Get raw note data without parsing:
Entry Specification
LastPass entries can be specified by:- Name:
"GitHub" - ID:
"1234567890" - URL:
"github.com" - Group:
"Work/GitHub"
Usage Examples
Basic Credentials
Git Configuration
~/.gitconfig.tmpl
SSH Private Key from Notes
LastPass automatically parses notes as colon-separated key-value pairs:~/.ssh/id_rsa.tmpl
CamelCase Words are converted to camelCaseWords.
Raw Note Data
If the note doesn’t contain key-value pairs:~/.ssh/id_rsa.tmpl
AWS Credentials
API Tokens
~/.config/tokens.env.tmpl
Database Configuration
~/.config/db/config.yml.tmpl
NPM Configuration
~/.npmrc.tmpl
Advanced Usage
Multiple Entries
If a search returns multiple entries:Accessing Nested Fields
Using Entry IDs
Find the entry ID:Conditional Access
~/.gitconfig.tmpl
Structuring Notes in LastPass
For best results, structure your notes as key-value pairs:Configuration
Custom Command
Iflpass is not in your PATH:
~/.config/chezmoi/chezmoi.toml
Troubleshooting
Not Logged In
If you get “Error: Could not find decryption key”:Session Expired
Log in again:Entry Not Found
List all entries to find the correct name:Command Not Found
Ensure LastPass CLI is installed:Testing Templates
Test template functions:Verify Entry Data
Check what data is available:Best Practices
- Use descriptive names: Name entries clearly for easy reference
- Structure notes: Use key-value format in notes for easy parsing
- Use folders: Organize entries in folders (
Work/GitHub,Personal/AWS) - Test entries: Verify entries are accessible before using in templates
- Stay logged in: Keep your LastPass session active on trusted machines
- Use entry IDs: For stability, consider using entry IDs instead of names