Getting started with 1Password for your growing team, or refining your setup? Our Secured Success quickstart guide is for you.
Forum Discussion
Nezteb
3 years agoNew Contributor
Feature Request: Generate random passwords with CLI via dedicated command (e.g. `op generate`)
There are a few past threads about this:
- December 2020: https://1password.community/discussion/117673/generating-passwords-with-the-cli
- March 2022: https://1password.community/discussion/1276...
Nezteb
3 years agoNew Contributor
Ah TIL about the --dry-run
flag, thanks for that tip!
Using your snippet as a base, I came up with a bash alias for this:
```
genpass() {
CHARS=${1:-32}
ITEM=$(op item create \
--dry-run \
--category Password \
--generate-password="letters,digits,symbols,$CHARS" \
--format json)
PASS=$(echo "$ITEM" | jq -r '.fields[] | select(.id == "password").value')
echo "$PASS"
}
```
That could all be one or two lines but I split it up for ease-of-use. 😅
Usage:
```
❯ genpass
7FwhRY.Zp.BVWxUrqUxKPEQQx-u!PKa.
❯ genpass 5
n3F-L
❯ genpass 64
ngtstGwJ3KmJQ2fJ-MkVkCPNNCqHXt_k-j3szo4KvVeFHVi*J*P*b2xVxpdRWRA8
```