介绍
# Dashlane CLI
从命令行访问您的 Dashlane 保险库。对密码、安全笔记、机密和 OTP 代码进行只读访问。
## 安装
```bash brew install dashlane/tap/dashlane-cli ```
## 身份验证
首次同步以触发身份验证: ```bash dcli sync ```
**步骤:** 1. 输入您的 Dashlane 电子邮件 2. **⚠️ 重要:在浏览器中打开显示的 URL**(设备注册) 3. 输入通过电子邮件收到的验证码 4. 输入您的主密码
检查当前帐户: ```bash dcli accounts whoami ```
## 获取密码
```bash # Search by URL or title (copies password to clipboard by default) dcli p mywebsite dcli password mywebsite
# Get specific field dcli p mywebsite -f login # Username/login dcli p mywebsite -f email # Email dcli p mywebsite -f otp # TOTP 2FA code dcli p mywebsite -f password # Password (default)
# Output formats dcli p mywebsite -o clipboard # Copy to clipboard (default) dcli p mywebsite -o console # Print to stdout dcli p mywebsite -o json # Full JSON output (all matches)
# Search by specific fields dcli p url=example.com dcli p title=MyBank dcli p id=xxxxxx # By vault ID dcli p url=site1 title=site2 # Multiple filters (OR) ```
## 获取安全笔记
```bash dcli note [filters] dcli n [filters] # Shorthand
# Filter by title (default) dcli n my-note dcli n title=api-keys
# Output formats: text (default), json dcli n my-note -o json ```
## 获取机密
Dashlane 机密是用于敏感数据的专用内容类型。
```bash dcli secret [filters]
# Filter by title (default) dcli secret api_keys dcli secret title=api_keys -o json ```
## 其他命令
```bash # Sync vault manually (auto-sync every hour by default) dcli sync
# Lock the vault (requires master password to unlock) dcli lock
# Logout completely dcli logout
# Backup vault to current directory dcli backup dcli backup --directory /path/to/backup ```
## 配置
```bash # Save master password in OS keychain (default: true) dcli configure save-master-password true
# Disable auto-sync dcli configure disable-auto-sync true
# Enable biometrics unlock (macOS only) dcli configure user-presence --method biometrics
# Disable user presence check dcli configure user-presence --method none ```
## 各平台的持久化
### macOS
主密码默认存储在 **Keychain** 中。重启后依然有效。 ```bash dcli configure save-master-password true ```
### Linux (服务器/无头模式)
没有原生的钥匙串。选项包括: 1. **环境变量**(安全性较低,但简单): ```bash export DASHLANE_MASTER_PASSWORD="..." ``` 2. **本地加密文件**:`save-master-password true` 将其存储在 `~/.local/share/dcli/` 中 3. **外部机密管理器**(Vault、AWS Secrets 等)来注入变量
### Docker / CI
使用传递给容器的 `DASHLANE_MASTER_PASSWORD` 环境变量。 ```bash docker run -e DASHLANE_MASTER_PASSWORD="..." myimage ```
### SSO / 无密码
dcli 尚不支持 — 需要经典的主密码。
## 高级:注入机密
```bash # Inject secrets into environment variables dcli exec -- mycommand
# Inject into templated files dcli inject < template.txt > output.txt
# Read secret by path dcli read "dl://vault/secret-id" ```
## 示例
### 获取用于 2FA 的 OTP
```bash dcli p github -f otp # Returns: 123456 (25s remaining) ```
### 从保险库获取 SSH 密钥
将私钥存储在安全笔记中,然后: ```bash dcli n SSH_KEY | ssh-add - ```
### 脚本编写
```bash # Get password for a script PASSWORD=$(dcli p myservice -o console)
# Get JSON and parse with jq dcli p myservice -o json | jq -r '.[0].password' ```
## 故障排除
- **已锁定?** 运行 `dcli sync` 进行解锁 - **SSO 用户:** 需要安装 Chrome + 可视化界面 - **无密码:** 尚不支持 - **调试模式:** `dcli --debug <command>`
文档:https://cli.dashlane.com