Post

Bitwarden CLI — Quick Introduction

Quick Introduction on How To use Bitwarden CLI (ak bw)

Bitwarden CLI — Quick Introduction

Introduction

Bitwarden is an open-source password manager that has become very popular.

  • [Best Password Manager for Personal, Business & EnterpriseBitwarden](https://bitwarden.com/)

Besides the Desktop app and Browser extension you can interact with Bitwarden via a cli tool

Setup

Create an account on Bitwarden Web Vault for free.

  • The free tier includes unlimited devices, all the core functions and passkey management.
  • Premium tier costs only 1$ per month and you get access to more features. It is very cheap and incredibly good.

Install CLI tool by running:

  • MacOS
1
brew install bitwarden-cli
  • Linux

With node

1
npm install -g @bitwarden/cli

With snap

1
sudo snap install bw
  • Windows
1
winget install -e --id Bitwarden.CLI

Basic Use

Login

Login to generate a session key

1
bw login

Set environment variable BW_SESSION with your session key as an environment variable to not include it on every command.

1
2
3
4
5
6
7
8
9
# ? Email address: someone@gmail.com
# ? Master password: [hidden]
# ? Two-step login code: 11111
# You are logged in!
To unlock your vault, set your session key to the `BW_SESSION` environment variable. ex:
$ export BW_SESSION="*******"
> $env:BW_SESSION="*******"
You can also pass the session key to any command with the `--session` option. ex:
$ bw list items --session *******

Add the BW_SESSION generated into your ~/.bashrc or ~/.zshrc.

1
export BW_SESSION="**********"

Or for Windows Powershell add BW_SESSION to your $PROFILE

1
$env:BW_SESSION="************"

List items

For example, to list items without BW_SESSION

1
bw list items --session ******

Can be simplified with the following

1
bw list items

Search items

To search items run the following

1
bw list items --search {key}

For example, for bitwarden itself

1
bw list items --search bitwarden

Get item

You can show a single item by running

1
 bw get item bitwarden

This will only work if only one item for the key exists (in this case bitwarden).

Get item password

To get the password as a stdout run

1
 bw get password bitwarden.com

### Get item totp (aka verification code)

To get the totp as a stdout run

1
bw get totp bitwarden.com

### Get item notes

1
 bw get notes bitwarden.com

Templates

Templates are necessary in order to create items, to get the templates for item and folder:

item template

1
2
3
bw get template item

# {"passwordHistory":[],"revisionDate":null,"creationDate":null,"deletedDate":null,"organizationId":null,"collectionIds":null,"folderId":null,"type":1,"name":"Item name","notes":"Some notes about this item.","favorite":false,"fields":[],"login":null,"secureNote":null,"card":null,"identity":null,"reprompt":0}

folder template

1
2
3
 bw get template folder

# {"name":"Folder name"}

Create item

You can create items by using the item template.

1
bw get template item | jq ".name=\"Bitwarden\" | .login=$(bw get template item.login | jq '.username="username" | .password="mypassword"')" | bw encode | bw create item

Create attachment

1
bw create attachment --file ./myfile.txt --itemid 16b14c89-65b3-4231-bd2b-15051a6d8g77

Create folder

1
bw get template folder | jq '.name="My Folder"' | bw encode | bw create folder

Generate passwords

You can generate passwords by running

1
bw generate

If you’d like to create different types of passwords, you can customize de prompt. For example, to create a passphrase with words

1
bw generate -p --words 4

Or to replace the separator - with _

1
 bw generate -p --words 4 --separator _
This post is licensed under CC BY 4.0 by the author.