pass, also known as the Unix password store, is a simple, command-line-driven password manager that follows the Unix philosophy. It stores passwords in GPG-encrypted files, organized in a simple directory tree, and can be easily synchronized using Git. This guide will walk you through setting up pass, generating GPG keys, managing your passwords, and integrating it with Git for secure and version-controlled password management.
To install pass on Debian-based systems (like Ubuntu):
sudo apt install pass
pass relies on GPG (GNU Privacy Guard) for encrypting your passwords. You’ll need a GPG key pair to initialize your password store. If you don’t have one, you can generate a new key.
gpg --full-gen-key
During the key generation process, you’ll be prompted for several choices:
(1) RSA and RSA (default).4096 bits is recommended for strong security.1y for one year) or choose 0 for no expiration.After generating or if you already have a GPG key, you need to identify its Key ID. This ID will be used to initialize pass.
gpg --list-secret-keys --keyid-format LONG
Look for a line similar to sec rsa4096/YOUR_KEY_ID 2023-01-01 [SC] and copy the YOUR_KEY_ID part (e.g., 0x12345678ABCDEF).
First, initialize your password store with your GPG key ID. This creates the .password-store directory in your home directory.
pass init YOUR_GPG_KEY_ID
YOUR_GPG_KEY_ID with the key ID you identified in the previous step (e.g., 0x12345678ABCDEF).To add a new password, use pass insert. You can organize your passwords in a folder-like structure.
pass insert folder/title
pass insert social/facebook will create a file ~/.password-store/social/facebook.gpg.To retrieve and display a password, use pass show. You’ll be prompted for your GPG passphrase.
pass show folder/title
pass show social/facebookTo list all stored passwords, simply run pass or pass ls.
pass
# or
pass ls
This will show you the hierarchical structure of your password store.
One of the powerful features of pass is its seamless integration with Git. This allows you to synchronize your password store across multiple devices, maintain a history of changes, and easily recover previous versions of your passwords.
To initialize a Git repository within your password store:
pass git init
This command creates a .git directory inside ~/.password-store/.
To synchronize your password store with a remote repository (e.g., a private GitHub repository):
pass git remote add origin git@github.com:your_username/your_password_repo.git
pass git push -u origin master
git@github.com:your_username/your_password_repo.git with the actual SSH URL of your private repository.After making changes to your password store, you can push them to your remote repository:
pass git add .
pass git commit -m "Update passwords"
pass git push
To pull changes from the remote repository to another device:
pass git pull
Sometimes you need to store more than just a single password, such as a username, URL, or notes. pass supports multiline entries, allowing you to store structured information within a single password file.
pass insert -mTo create a multiline entry, use the -m flag with pass insert:
pass insert -m folder/title
This will open your default text editor (e.g., vi, nano) where you can type your multiline content. The first line will be treated as the primary password, and subsequent lines can be custom fields.
A common and recommended format for multiline entries includes fields like username, password, and URL:
your_password_here
username: your_username
url: https://example.com
notes: additional notes
When you pass show folder/title, only the first line (the password) will be displayed by default. To view the entire content, you can use pass show -c folder/title to copy the first line, or pass show folder/title | less to view the full file.
Your GPG private key is the master key to your password store. Losing it means losing access to all your encrypted passwords. Therefore, securely backing up your private key is critically important.
gpg –list-secret-keys –keyid-format LONG
```
Note down the YOUR_KEY_ID (e.g., 0x12345678ABCDEF).
Export Private Key (CRITICAL):
This is the most sensitive part. Store private-key-backup.asc in a very secure location (e.g., encrypted USB drive, secure cloud storage, hardware security module).
gpg –export-secret-keys –armor YOUR_KEY_ID > private-key-backup.asc ```
Export Public Key (Optional but Recommended): While not as sensitive, backing up your public key is good practice, especially if you share it or need it for verification.
gpg –export –armor YOUR_KEY_ID > public-key-backup.asc ```
If you need to restore your GPG keys on a new system or after a loss:
gpg –import private-key-backup.asc ``` You will be prompted for the passphrase of the private key.
gpg –import public-key-backup.asc ```
pass stands out as a powerful, secure, and flexible password manager that aligns perfectly with the Unix philosophy of doing one thing well. By leveraging GPG encryption and Git for synchronization, it provides a robust solution for managing your digital credentials. Integrating pass into your daily workflow can significantly enhance your security posture and streamline access to your sensitive information.