| name | 1password |
| description | Complete 1Password CLI (op) for managing secrets, credentials, and secure storage. Use when working with: (1) Retrieving passwords, API keys, and secrets from vaults, (2) Managing items, documents, and secure notes, (3) Injecting secrets into environment variables and config files, (4) Automating credential rotation and management, (5) Accessing SSH keys and certificates, (6) Vault and item CRUD operations, (7) Secret references for CI/CD pipelines, (8) User and group management. |
1Password CLI Skill
Complete 1Password operations for secure secret management and automation.
Authentication
Before using any op commands, you must authenticate:
op signin
op account list
op whoami
op signout
Once signed in, your session remains active for CLI operations.
Vault Management
List and Get Vaults
op vault list
op vault list --format json
op vault get <vault-name-or-id>
op vault get "Private"
op vault get "Work"
Create and Manage Vaults
op vault create <vault-name>
op vault create "DevOps Secrets"
op vault delete <vault-name-or-id>
op vault user grant --vault <vault-id> --user <user-email>
op vault user revoke --vault <vault-id> --user <user-email>
Item Management
Retrieving Items
op item list
op item list --vault "Private"
op item list --categories Login
op item list --tags production
op item list --format json
op item get <item-name-or-id>
op item get "GitHub Token"
op item get "AWS Credentials" --vault "Work"
op item get "GitHub Token" --format json
Retrieving Specific Fields
op item get <item-name> --fields <field-name>
op item get "GitHub Token" --fields token
op item get "AWS Credentials" --fields "access key"
op item get "Database" --fields password
op item get "AWS Credentials" --fields "access key,secret key" --format json
op read "op://<vault>/<item>/<field>"
op read "op://Private/GitHub Token/token"
op read "op://Work/AWS Credentials/access key"
Creating and Updating Items
op item create --category Login \
--title "New Service" \
--vault "Private" \
--url "https://example.com" \
username=user@example.com \
password=<generate-password>
op item create --category Password \
--title "API Key" \
--vault "Work" \
api_key=sk-xxx \
environment=production
op item create --category "Secure Note" \
--title "Deployment Notes" \
--vault "Work" \
notesPlain="Important deployment information"
op item edit <item-name> <field>=<value>
op item edit "GitHub Token" token=ghp_newtoken123
op item edit "AWS Credentials" --tags production,terraform
op item edit "Database Login" password=<generate-password>
Deleting Items
op item delete <item-name-or-id>
op item delete "Old API Key" --vault "Work"
op item delete "Old Token" --archive
Secret References
Use secret references to inject 1Password secrets into applications without exposing them:
op://[vault]/[item]/[field]
op://Private/GitHub Token/token
op://Work/AWS Credentials/access key
op://DevOps/Database/password
op run -- env
op run -- npm run build
op run -- terraform apply
echo 'DB_PASSWORD=op://Work/Database/password' | op inject
cat .env.template | op inject > .env
Environment Variable Injection
cat <<EOF > .env.template
DATABASE_URL=op://Work/Database/connection_string
API_KEY=op://Work/Service/api_key
SECRET_TOKEN=op://Work/Service/secret
EOF
op inject -i .env.template -o .env
cat .env.template | op inject > .env
op run --env-file=.env.template -- node app.js
Document Management
op document list
op document get <document-name> --output <local-path>
op document get "SSL Certificate" --output ./cert.pem
op document create <file-path> --title "Document Name" --vault "Work"
op document create ./config.yaml --title "K8s Config" --vault "DevOps"
op document delete <document-name>
SSH Key Management
op item list --categories "SSH Key"
op item get "GitHub SSH Key" --fields "private key" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
op item get "GitHub SSH Key" --fields "public key" > ~/.ssh/id_rsa.pub
op read "op://Private/GitHub SSH Key/private key" > ~/.ssh/id_rsa
Password Generation
op item create --generate-password
op item create --generate-password=<length>,letters,digits,symbols
op item create --category Login \
--title "New Service" \
--generate-password=32,letters,digits,symbols
op generate --length 20 --symbols
op generate --length 6 --digits
User and Group Management
op user list
op user get <user-email>
op user provision --email user@example.com --name "User Name"
op user suspend <user-email>
op user confirm <user-email>
op group list
op group get <group-name>
op group user grant --group <group-name> --user <user-email>
op group user revoke --group <group-name> --user <user-email>
Template-Based Item Creation
op item template list
op item template get Login
op item template get Password
op item template get "API Credential"
cat <<EOF | op item create -
{
"vault": "Work",
"title": "New API",
"category": "API_CREDENTIAL",
"fields": [
{
"id": "username",
"type": "STRING",
"label": "username",
"value": "api_user"
},
{
"id": "credential",
"type": "CONCEALED",
"label": "credential",
"value": "secret_api_key"
}
]
}
EOF
Common Workflows
Automated Secret Rotation
CURRENT_KEY=$(op item get "Service API" --fields api_key)
NEW_KEY=$(curl -X POST https://api.service.com/rotate \
-H "Authorization: Bearer $CURRENT_KEY")
op item edit "Service API" api_key="$NEW_KEY"
CI/CD Integration
op item create --category Password \
--title "GitHub Actions Token" \
--vault "CI/CD" \
token=ghp_xxxxx
op run --env-file=.env.template -- ./deploy.sh
export GITHUB_TOKEN=$(op read "op://CI/CD/GitHub Actions Token/token")
Backup Configuration with Secrets
cat <<EOF > config.template.yaml
database:
host: db.example.com
user: op://Work/Database/username
password: op://Work/Database/password
api:
key: op://Work/API/key
secret: op://Work/API/secret
EOF
op inject -i config.template.yaml -o config.yaml
op run --env-file=config.template.yaml -- ./app
SSH Key Deployment
op item get "GitHub Deploy Key" --fields "private key" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
cat <<EOF >> ~/.ssh/config
Host github-deploy
HostName github.com
User git
IdentityFile ~/.ssh/deploy_key
EOF
git clone git@github-deploy:org/repo.git
Database Connection Strings
op item create --category Password \
--title "Production DB" \
--vault "Work" \
connection_string="postgresql://user:pass@host:5432/db"
export DATABASE_URL=$(op item get "Production DB" --fields connection_string)
psql "$DATABASE_URL"
op run -- psql $(op read "op://Work/Production DB/connection_string")
Output Formats
op item list --format json
op vault list --format json
op item get "Item" --format json
op item list
op item list --format json | jq '.[] | select(.vault.id == "vaultid")'
op item get "AWS" --format json | jq -r '.fields[] | select(.label == "access key") | .value'
Advanced Filtering and Queries
op item list --categories Login,Password
op item list --categories "API Credential"
op item list --tags production
op item list --tags "production,critical"
op item list --vault "Work"
op item list --vault "Work" --categories Login --tags production --format json
op item list --format json | jq '.[] | select(.title | contains("AWS"))'
Service Account Integration
For automation and CI/CD without human interaction:
export OP_SERVICE_ACCOUNT_TOKEN=<token>
op item list
op read "op://Work/API/key"
echo $OP_SERVICE_ACCOUNT_TOKEN | op signin
op run -- ./deploy.sh
Shell Plugins
1Password CLI integrates with shell for autocompletion and aliases:
eval "$(op completion zsh)"
eval "$(op completion bash)"
Error Handling
if op item get "Service Token" &>/dev/null; then
TOKEN=$(op item get "Service Token" --fields token)
else
echo "Item not found"
exit 1
fi
TOKEN=$(op item get "Service" --fields token 2>/dev/null || echo "")
if [ -z "$TOKEN" ]; then
echo "Token field not found"
fi
if ! op account list &>/dev/null; then
echo "Not signed in to 1Password"
op signin
fi
Security Best Practices
- Use Secret References: Always use
op:// references in templates instead of hardcoding secrets
- Limit Service Account Permissions: Create service accounts with minimal required vault access
- Rotate Regularly: Automate secret rotation workflows
- Audit Access: Regularly review vault access and user permissions
- Use Categories: Organize items by category for better access control
- Tag Appropriately: Use tags for environment (prod, staging) and criticality
- Document Items: Add notes and metadata to items for context
- Never Log Secrets: When using
op run, ensure applications don't log injected secrets
Troubleshooting
op --version
brew upgrade 1password-cli
op signout --all
op item get "Item" --debug
op account list
op whoami
op vault list
op vault get "Vault Name"
Integration Examples
Terraform
# .env.template
export TF_VAR_api_key=op://Work/Service/api_key
export TF_VAR_secret=op://Work/Service/secret
# Run terraform with injected secrets
op run --env-file=.env.template -- terraform apply
Docker Compose
services:
app:
environment:
DB_PASSWORD: op://Work/Database/password
API_KEY: op://Work/Service/api_key
op run -- docker-compose -f docker-compose.template.yml up
Kubernetes
kubectl create secret generic app-secrets \
--from-literal=api-key=$(op read "op://Work/API/key") \
--from-literal=db-password=$(op read "op://Work/DB/password")
For more information, see the 1Password CLI documentation.