The Bitwarden Blog

How to install and use the Bitwarden command line tool

dont l'auteur est:Jack Wallen
Link Copied!
  1. Blog
  2. How to install and use the Bitwarden command line tool

Bitwarden is one of the most robust, well-designed password managers on the planet. Not only is it a great solution for individuals but also for teams and other types of organizations. But there's another reason why this open-source password manager makes for a great addition to anyone's security toolkit… it offers a command-line version as well.

Imagine, you use Bitwarden on your desktops as your go-to password manager. But you also work with a lot of GUI-less servers, or you may just simply prefer the command line over graphical tools. If that's you, you'll be happy to know Bitwarden has you covered. And although the command-line version of the tool isn't quite as user-friendly as the GUI, it's still a valuable option for those who work within a terminal.

The command-line version of Bitwarden can be installed on Linux, macOS, and Windows by way of either a native installer, a snap package, via npm, or the Chocolatey package manager for Windows. I'm going to walk you through the steps to install the Bitwarden CLI tool on Linux Server 22.04 and then show you how to create a new entry and then view a password for an entry.

The main caveat to using the Bitwarden CLI tool is that adding items can be very complicated and doesn't always work as expected. Because of that, I highly recommend you use it only to view items and not add them.

Installing the Bitwarden CLI tool

The first thing we'll do is install the Bitwarden CLI tool. Since I'm using Ubuntu Server 22.04 as my test case, I can easily install the app with snap. Log in to your Ubuntu instance and issue the command:

sudo snap install bw

Let's also install the jq JSON processor with:

sudo snap install jq

If you opt to go the binary route installation, it can be accomplished with these steps:

  1. Download the zipped file from the Bitwarden download page.

  2. Install unzip with sudo apt-get install unzip -y.

  3. Unzip the downloaded file with unzip (Where X is the release number).

  4. Give the binary executable permissions with chmod u+x bw.

  5. Move the executable to a directory in your path with sudo mv bw /usr/local/bin.

How to log in with the Bitwarden CLI tool

You'll now need to log in to your Bitwarden account with the command:

bw login

You'll be prompted for your Bitwarden email address, master password, and (if applicable) the two-step login code. Once you've successfully logged in, you'll be greeted with You are now logged in! and you're ready to go.

How to view an item in your vault

The first thing we'll do is locate a password in your vault. To do that, you'll need to know the name of the item. Let's say you have an entry for GitHub in your vault. To view that item, you'd issue the command:

bw get password GitHub

If you happen to have multiple entries associated with GitHub, you'll be warned and the bw command will list the object IDs for all of the entries. With the ID in hand, you could view the password like so:

bw get password ID

Where ID is the ID for the entry. Once you successfully enter your master password, the password for the item will be revealed.

How to create a folder

Remember when I said creating an item from the command line is complicated? That wasn't hyperbole. However, I want to demonstrate how it's done anyway. What I'll do is show you the workflow by way of creating a new folder (for our example, the folder will be named FINANCES). Here's how it works:

  1. Retrieve the template for creating a folder with the command bw get template folder. The output for this command will be {“name”:”Folder name”}. Simple enough.

  2. Create an encode key for the new folder with the command echo '{"name":"FINANCES"}' | bw encode.

  3. The output will be a random string of characters. Copy that string and then paste it into the command bw create folder STRING (Where STRING is the random string of characters).

If you then issue the command bw get folder FINANCES, you'll see output like this:


The item creation is much more complicated because there are far more pieces to configure. If you issue the command bw get template item, the output looks like this:

{"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}

You have to go through the same steps for creating an item as you did a folder (only configuring it in line with the above output).

And that's the basics for using the Bitwarden Command Line Tool. As I mentioned earlier, I recommend using this as a tool for viewing passwords on a server without a GUI or a desktop where you prefer working from the CLI. I don't, however, recommend using this tool as your only means of interacting with your Bitwarden Vault, as that can become a cumbersome workflow.

About the Author

Jack Wallen is an award-winning author and avid supporter of open source technologies. He has covered open source, Linux, security, and more for publications including TechRepublic, CNET, ZDNet, The New Stack, Tech Target and many others since the 1990s in addition to writing over 50 novels.

Link Copied!
Retour au blog

Get started with Bitwarden today.

Créez votre compte gratuit

© 2024 Bitwarden, Inc. Conditions Confidentialité Paramètres des cookies Plan du site

Go to EnglishStay Here