bitwarden

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Bitwarden CLI

Bitwarden CLI

Retrieve secrets when environment variables are missing.
当环境变量缺失时获取机密信息。

CRITICAL: Source .env Before EVERY bw Command

重要提示:在执行每个bw命令前先执行source .env

EVERY
bw
command MUST be prefixed with sourcing .env
to load
BW_SESSION
:
bash
undefined
所有
bw
命令必须以
source .env
为前缀
,以载入
BW_SESSION
环境变量:
bash
undefined

Standard prefix for ALL bw commands - copy this pattern exactly:

所有bw命令的标准前缀——完全复制此格式:

source .env 2>/dev/null; bw <command>

Example commands:
```bash
source .env 2>/dev/null; bw status
source .env 2>/dev/null; bw list items --search "telegram"
source .env 2>/dev/null; bw get password "item-name"
source .env 2>/dev/null; bw get notes "item-name"
If .env is in a parent directory, search up:
bash
for dir in . .. ../.. ../../..; do [[ -f "$dir/.env" ]] && source "$dir/.env" && break; done; bw status
source .env 2>/dev/null; bw <command>

示例命令:
```bash
source .env 2>/dev/null; bw status
source .env 2>/dev/null; bw list items --search "telegram"
source .env 2>/dev/null; bw get password "item-name"
source .env 2>/dev/null; bw get notes "item-name"
如果.env文件位于上级目录,向上搜索:
bash
for dir in . .. ../.. ../../..; do [[ -f "$dir/.env" ]] && source "$dir/.env" && break; done; bw status

Session Management

会话管理

Check status (should show "unlocked" if BW_SESSION is valid):
bash
source .env 2>/dev/null; bw status
If locked and BW_SESSION not in .env, unlock and save to .env:
bash
echo "BW_SESSION=$(bw unlock --raw)" >> .env
检查状态(如果BW_SESSION有效,应显示"unlocked"):
bash
source .env 2>/dev/null; bw status
如果密码库已锁定且.env中没有BW_SESSION,解锁并保存到.env:
bash
echo "BW_SESSION=$(bw unlock --raw)" >> .env

Finding API Keys

查找API密钥

API keys are often stored in notes - either in a login item's notes field or as a standalone secure note.
  1. Search first to find the right item:
    bash
    bw list items --search "openai"
  2. Check notes - API keys are commonly here:
    bash
    bw get notes "item-name"
  3. Check custom fields if not in notes:
    bash
    bw get item "item-name" | jq -r '.fields[] | select(.name=="API_KEY") | .value'
API密钥通常存储在备注中——要么在登录项的备注字段,要么作为独立的安全备注。
  1. 先搜索找到对应的条目:
    bash
    bw list items --search "openai"
  2. 查看备注——API密钥通常在这里:
    bash
    bw get notes "item-name"
  3. 如果备注中没有,检查自定义字段:
    bash
    bw get item "item-name" | jq -r '.fields[] | select(.name=="API_KEY") | .value'

Common Patterns

常见用法示例

NeedCommand
Search items
bw list items --search "query"
Notes (API keys!)
bw get notes "name"
Password
bw get password "name"
Username
bw get username "name"
TOTP
bw get totp "name"
Custom field
bw get item "name" | jq -r '.fields[] | select(.name=="FIELD") | .value'
需求命令
搜索条目
bw list items --search "query"
查看备注(含API密钥!)
bw get notes "name"
获取密码
bw get password "name"
获取用户名
bw get username "name"
获取TOTP
bw get totp "name"
获取自定义字段
bw get item "name" | jq -r '.fields[] | select(.name=="FIELD") | .value'

CLI Help

CLI帮助

bw [options] [command]

Commands:
  login [email] [password]    Log into account
  unlock [password]           Unlock vault, returns session key
  lock                        Lock vault
  status                      Show vault status
  list <object>               List objects (items, folders, collections)
  get <object> <id>           Get object (item, username, password, totp, notes)
  sync                        Pull latest vault data
bw [options] [command]

Commands:
  login [email] [password]    登录账户
  unlock [password]           解锁密码库,返回会话密钥
  lock                        锁定密码库
  status                      显示密码库状态
  list <object>               列出对象(条目、文件夹、集合)
  get <object> <id>           获取对象(条目、用户名、密码、TOTP、备注)
  sync                        拉取最新的密码库数据