Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active June 5, 2025 08:51
Show Gist options
  • Save Integralist/5010e113ce19285698cfe5d941b9884b to your computer and use it in GitHub Desktop.
Save Integralist/5010e113ce19285698cfe5d941b9884b to your computer and use it in GitHub Desktop.
1Password CLI #shell

list all accounts

op account list

check which account we're using

op whoami

switch account

op signin
op signin --account my # account flag must be passed subset of the URL from `op account list` (e.g. `my` matches `my.1password.com`)

list all vaults

op vault list --format json

list all items within the "Private" vault

op item list --vault "Private" --format json

get a specific item from the "Private" vault

op item get "Your Item Title" --vault "Private" --format json

get the password from a specific item from the "Private" vault

op item get "Your Item Title" --vault "Private" --fields password --reveal

use 1Password "secret reference" wherever you need a secret to be used.

e.g. an application config file or even an environment variable exported as part of a shell script.

format:

op://<VAULT_NAME>/<ITEM_NAME>/<FIELD>

you can easily get the reference to any field using the 1Password GUI.

op read "op://Private/Fastly API Tokens/Integralist-PersonalAllServices/Token"
op inject -i some_input_file.tpl -o the_output_file_with_secret

export FASTLY_API_TOKEN=$(op read "op://Private/Fastly API Tokens/Integralist-PersonalAllServices/Token")
export FASTLY_API_TOKEN=$(echo "op://Private/Fastly API Tokens/Integralist-PersonalAllServices/Token" | op inject)

curl -sX GET "https://api.cloudflare.com/client/v4/user/tokens/verify" -H "Authorization: Bearer $(op read 'op://Private/6bky6ykumav2wfpguwn4dokcku/API Token')" -H "Content-Type:application/json" | jq
curl -sX GET "https://api.cloudflare.com/client/v4/user/tokens/verify" -H "Authorization: Bearer $(echo 'op://Private/6bky6ykumav2wfpguwn4dokcku/API Token' | op inject)" -H "Content-Type:application/json" | jq

Note

When entering a title for a 1Password entry, the use of a : will cause the "Copy Secret Reference" feature to use a cryptic hash instead of a descriptive name. If you want to find the entry this secret reference is related to, then you can search in 1Password using the hash, but from a documentation perspective I much prefer the "descriptive" version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment