How to install Bitwarden Server with Sendgrid SMTP on Ubuntu 20.04
This article will guide you on how to install self-hosted Bitwarden password manager on Ubuntu Server 20.04. Bitwarden is an “open-source password manager which stores sensitive information such as website passwords in an encrypted vault”. Bitwarden is available for individual and organizational use in both free and paid plans. In this tutorial, we will be learning how to install and setup free version of Bitwarden on Ubuntu 20.04.
Requirements
- 2GB RAM
- 15GB Storage
- A user with administrative privileges
- Sendgrid account
Step 1: Update the system
Lets start off by updating the package index as follows.
sudo apt update
Step 2: Install Dependencies
Some dependencies are required for the bitwarden installation so we install them with the following command.
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Step 3: Install Docker and Docker Compose
We are going to use Docker containers to deploy bitwarden with the help of Docker Compose.
But first, let’s Add the Docker GPG key. To do this, switch to root user or run the command as super user and execute:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Next, add the official repository of Docker on your system to get its latest version for installation.
sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”
Run system update
sudo apt update
Finally, install Docker, Docker compose and other crucial Docker tools as follows.
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose
Step 4: Create a User for Bitwarden
For good security practice, let’s create a separate and dedicated user for Bitwarden server installation on Ubuntu 20.04 without any sudo access.
Add the user
sudo adduser bitwarden
Add the bitwarden user to the docker group:
sudo usermod -aG docker bitwarden
Create a dedicated directory for the bitwarden user:
sudo mkdir /opt/bitwarden
Grant the bitwarden user full permission to the directory
sudo chown -R bitwarden:bitwarden /opt/bitwarden
sudo chmod -R 700 /opt/bitwarden
Switch to bitwarden user
su bitwarden
Step 5: Download Bitwarden Installation Script
Run the command below to download the Bitwarden installation script.
curl -Lso bitwarden.sh https://go.btwrdn.co/bw-sh && chmod 700 bitwarden.sh
Then install Bitwarden password manager.
./bitwarden.sh install
- Enter the domain name you would like to use to access your bitwarden server ie bitwarden.your-domain.com
- When it asks to issue a free SSL certificate, type n
- Now enter the database name for your Bitwarden instance ie vault.
After that, the script will start downloading and creating the containers it requires.
Add Bitwarden Installation ID and Key
The installation of Bitwarden requires you to provide an installation key and ID.
Visit https://bitwarden.com/host and simply add any email ID in the input box to get the ID and Key.
Once you click the ‘Submit’ button, you will get the following page that contains a unique installation Id and key for your installation.
Step 6: Configuring Sendgrid SMTP Mail Server
Admin login is not possible without an SMTP server. The Portal uses a secure means of password-less authentication. When an admin user attempts to log in, a secure link is sent to their email address only if that email address is specified in adminSettings__admins= of the global.override.env file.
- Create a Sendgrid account to generate an apikey also verify sender authentication under your account settings.
- Now lets edit our global.override.env file to set our SMTP values.
nano ~/bwdata/env/global.override.env
Step 7: Start the Server
Now lets run the server to finally activate all the containers and ports.
./bitwarden.sh start
To access the Bitwarden web interface, open your web browser and enter the domain name you set for your bitwarden server. ie
https://bitwarden.your-domain.com
- Create a new account in order to access your vault
- Now login with your details to access your vault
- To get the Admin backend access, add the /admin at the end of the domain you are using.
i.e https://bitwarden.your-domain.com/admin
- Enter the email you added to the global.override.env under adminSettings__admins and a login link will be sent to your email.
Step 8: Setting Up the Client Application
- Download the Bitwarden client from their official website as per your operating system.
- After installing the client, run it and click on the Gear icon.
- Add your Bitwarden Server URL where you have installed it. And click on the Save button.
- Then create an account or login to your pre-existing account.
Delete or reinstall the Bitwarden server
In case, you got an issue and want to reinstall the Server and its containers then the first login to its user and then run:
- To delete
./bitwarden.sh stop
rm -r ~/bwdata
- To reinstall run
./bitwarden.sh install
- To delete all containers build for the server run,
docker stop $(docker ps -a -q)
docker rm -f $(docker ps -a -q)
Congratulations! You can now safely store your passwords and other confidential information in your Bitwarden vault. Enjoy.