# Bitwarden
A quick guide that condenses the [Linux Standard Deployment](https://bitwarden.com/help/install-on-premise-linux/) instructions

## Install Docker
Follow [Docker's guide](https://docs.docker.com/engine/install/ubuntu/) or do this:

```
# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update
```

And then this:

```
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
```

## Install Bitwarden

### Add a bitwarden user
```
sudo adduser bitwarden
```

### Set the password
```
sudo passwd bitwarden
```

### Create docker group and add bitwarden user to it
```
# Add group if it doesn't exist
sudo groupadd docker

# Add bitwarden user to it
sudo usermod -aG docker bitwarden
```

### Prep install directory
```
# Create a directory for bitwarden install
sudo mkdir /opt/bitwarden

# Set permissions
sudo chmod -R 700 /opt/bitwarden

# Set owner
sudo chown -R bitwarden:bitwarden /opt/bitwarden
```

### Install the software
```
# IMPORTANT!  Change to the bitwarden user first!
sudo su - bitwarden

# Grab the install script
curl -Lso bitwarden.sh "https://func.bitwarden.com/api/dl/?app=self-host&platform=linux" && chmod 700 bitwarden.sh

# Run it
./bitwarden.sh install
```

### Edit the main config file
Do a `nano ~/bwdata/env/nano global.override.env` and then, at a minimum, populate these fields so users can get emails when they register for your site:

```
globalSettings__mail__replyToEmail=no-reply@yoursite.com
globalSettings__mail__smtp__host=some.smtp.server
globalSettings__mail__smtp__port=587
globalSettings__mail__smtp__ssl=true
globalSettings__mail__smtp__username=mail@yoursite.com
globalSettings__mail__smtp__password=xyz123
```

Then restart Bitwarden:

```
./bitwarden.sh restart
```

Finally, if you're like me and you want to disable user registrations after the Bitwarden admins have registered, open up the config file one more time and set this setting:

```
globalSettings__disableUserRegistration=true
```

And then do one final:

```
./bitwarden.sh restart
```
