cheat-sheets

1Password CLI Cheat-Sheet

The 1Password CLI (op) reads and writes vault items from the terminal and injects secrets into commands and config files without writing them to disk. Use it to keep secrets out of .env files and shell history.

Documentation: 1Password CLI Project: 1Password

Related sheets: Bitwarden, pass, gopass, LastPass CLI, SOPS and age, Secret Scanning.

Install and Update #

COMMANDDESCRIPTION
brew install 1password-cliInstall on macOS
winget install 1password-cliInstall on Windows
op --versionCheck the install
op updateCheck for and download a newer op
op update --channel beta --directory <PATH>Pick the channel (stable or beta) and download location

On Linux, use the package repository or the zip from the 1Password downloads page; see the install page in the documentation.

Sign In #

With the desktop app installed, turn on the CLI integration (Settings, Developer) and op signs in through the app (Touch ID and similar). Without it, sign in by hand.

COMMANDDESCRIPTION
op signinSign in to an account (prompts if needed)
eval $(op signin --account <SHORTHAND>.1password.com)Sign in and export the session token for this shell (manual sign-in only)
op whoamiShow which account or service account is active
op account listList signed-in accounts
op signoutSign out

Global Flags and Variables #

FLAG OR VARIABLEDESCRIPTION
--account <ACCOUNT> / OP_ACCOUNTPick the account when you have several
--format json / OP_FORMATOutput JSON instead of a table
--vault <VAULT>Limit a command to one vault (per-command flag)
--cache=false / OP_CACHETurn the item cache off or on
--debug / OP_DEBUGPrint debug output
OP_ISO_TIMESTAMPSUse ISO 8601 timestamps in output

Secret References #

A secret reference points at a field instead of holding its value. Format: op://VAULT/ITEM/[SECTION/]FIELD. Names and IDs both work.

COMMANDDESCRIPTION
op read "op://app-prod/db/password"Print one field
op read "op://app-prod/db/one-time password?attribute=otp"Print the current one-time password
op read --out-file ./key.pem op://app-prod/server/ssh/key.pemSave a file or key field to disk
op read --no-newline op://app-prod/db/passwordDrop the trailing newline

Quote references that contain spaces or ?.

Run Commands With Secrets #

op run swaps secret references in the environment for real values for the child process only.

COMMANDDESCRIPTION
op run --env-file=.env -- <COMMAND>Load references from an env file and run the command
op run -- <COMMAND>Resolve references already in the environment
op run --no-masking -- <COMMAND>Do not mask secrets in the command output (masking is on by default)
op run --environment <ENVIRONMENT_ID> -- printenvLoad a 1Password Environment
bash
# .env holds references, not secrets
# DB_PASSWORD=op://app-prod/db/password
op run --env-file=.env -- docker compose up -d

Inject Into Config Files #

op inject fills {{ op://... }} placeholders in a template.

COMMANDDESCRIPTION
op inject -i config.yml.tpl -o config.ymlRender a template to a file
echo "db_password: {{ op://app-prod/db/password }}" | op injectRender from stdin to stdout
op inject --in-file <TEMPLATE> --out-file <FILE> --forceOverwrite the output file without asking

Do not commit the rendered file; see Secret Scanning.

Items #

COMMANDDESCRIPTION
op item listList items
op item list --vault <VAULT> --tags <TAG> --categories LoginFilter the list
op item list --long --favoriteMore detail, favourites only
op item get "<ITEM>"Show an item
op item get "<ITEM>" --fields label=username,label=passwordPick fields by label
op item get "<ITEM>" --fields type=concealed --revealPick fields by type and show hidden values
op item get "<ITEM>" --otpPrint the one-time password
op item get "<ITEM>" --share-linkGet a shareable link
op item get "<ITEM>" --format jsonFull item as JSON
op item create --category login --title "<TITLE>" --vault <VAULT> --url <URL> 'username=<USER>'Create a login
op item create --category login --title "<TITLE>" --generate-password='letters,digits,symbols,32'Create with a generated password
op item create --dry-run ...Preview without saving
op item edit "<ITEM>" 'field=<VALUE>'Change a field
op item edit "<ITEM>" --generate-password='letters,digits,symbols,32'New generated password
op item edit "<ITEM>" 'section.field[delete]'Delete a field
op item move "<ITEM>" --current-vault <FROM> --destination-vault <TO>Move to another vault
op item share "<ITEM>" --emails <EMAIL> --expires-in 24h --view-onceShare a link that expires
op item delete "<ITEM>" --archiveMove to the Archive (without --archive the delete is permanent)
op item template listList item categories
op item template get <CATEGORY> --out-file <FILE>Get a JSON template for a category

Assignments use section.field[type]=value; types include text, password, phone and monthyear.

Documents #

COMMANDDESCRIPTION
op document listList documents
op document create <FILE> --title "<TITLE>" --vault <VAULT>Upload a file
op document get "<TITLE>" --out-file <FILE>Download a file
op document edit "<TITLE>" <FILE>Replace the file
op document delete "<TITLE>" --archiveArchive the document

Vaults #

COMMANDDESCRIPTION
op vault listList vaults
op vault get <VAULT>Show a vault
op vault create <NAME> --description "<TEXT>"Create a vault
op vault edit <VAULT> --name <NEW_NAME>Rename a vault
op vault edit <VAULT> --travel-mode onTurn Travel Mode on or off
op vault delete <VAULT>Delete a vault
op vault group list <VAULT>Show which groups can access it
op vault group grant --vault <VAULT> --group <GROUP> --permissions <PERMISSIONS>Give a group access
op vault group revoke --vault <VAULT> --group <GROUP>Remove access

Scripts and CI #

COMMANDDESCRIPTION
OP_SERVICE_ACCOUNT_TOKEN=<TOKEN> op vault listAuthenticate non-interactively with a service account (unverified here: variable name not in the pages checked, see the service accounts page)
op item list --format json | jq -r '.[].title'Parse JSON output with jq
op item list --tags <TAG> --format json | op item get - --fields label=passwordPipe a list into get

Keep the token in your CI secret store, never in the repository.

Troubleshooting #

SYMPTOMFIX
not signed in or a prompt in scriptsRun op whoami; use the app integration or a service account for scripts
Wrong accountPass --account or set OP_ACCOUNT
Reference not foundCheck names with op item get; quote names that contain spaces
Secret printed in plain outputPrefer op run (masks output) over op read in logs

See Also #

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.