本教程适用于以下操作系统版本
- Ubuntu 22.04 (Jammy Jellyfish)
- Ubuntu 20.04 (Focal Fossa)
本页内容
- 先决条件
- 开始使用
- 安装 Docker CE 仓库
- 安装 Docker CE
- 安装 Docker Compose
- 为 Bitwarden 创建用户
- 在 Ubuntu 22.04 上安装 Bitwarden 密码管理器
- 访问 Bitwarden Web 界面
- 结论
Bitwarden 是一款免费且开源的密码管理器,可让你存储所有的登录凭据和密码,并在所有设备之间同步。它是跨平台的,可用于 Linux 以及所有其他主流操作系统,例如 Windows 和 macOS。它拥有许多实用功能,包括强加密、双因素认证(2FA)、密码安全审计、密码泄露监控,以及云端或本地托管选项。
在本文中,我们将向你展示如何在 Ubuntu 22.04 上安装 Bitwarden 密码管理器软件。
先决条件
- 一台运行 Ubuntu 22.04 的服务器。
- 服务器上已配置 root 密码。
开始使用
首先,建议将所有系统软件包更新并升级到最新版本。你可以运行以下命令来更新它们:
apt update -y
apt upgrade -y
所有软件包升级完成后,运行以下命令安装其他所需的依赖:
apt install apt-transport-https ca-certificates curl software-properties-common -y
所有依赖安装完成后,即可进入下一步。
安装 Docker CE 仓库
接下来,你需要将 Docker CE 官方仓库添加到 APT。首先,使用以下命令添加 Docker GPG 密钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
接下来,使用以下命令添加 Docker CE 仓库:
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu jammy stable"
将 Docker 仓库添加到 APT 后,即可进入下一步。
安装 Docker CE
现在,你可以使用以下命令安装最新版本的 Docker CE:
apt install docker-ce -y
Docker 安装完成后,使用以下命令检查 Docker 服务的状态:
systemctl status docker
你将在以下输出中看到 Docker 的状态:
? docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-08-28 05:52:18 UTC; 47s ago
TriggeredBy: ? docker.socket
Docs: https://docs.docker.com
Main PID: 2719 (dockerd)
Tasks: 7
Memory: 30.3M
CPU: 312ms
CGroup: /system.slice/docker.service
??2719 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Aug 28 05:52:18 ubuntu2204 dockerd[2719]: time="2022-08-28T05:52:18.379341986Z" level=info msg="scheme \"unix\" not registered, fallback to d>
Aug 28 05:52:18 ubuntu2204 dockerd[2719]: time="2022-08-28T05:52:18.379467088Z" level=info msg="ccResolverWrapper: sending update to cc: {[{u>
Aug 28 05:52:18 ubuntu2204 dockerd[2719]: time="2022-08-28T05:52:18.379593467Z" level=info msg="ClientConn switching balancer to \"pick_first>
Aug 28 05:52:18 ubuntu2204 dockerd[2719]: time="2022-08-28T05:52:18.427861369Z" level=info msg="Loading containers: start."
Aug 28 05:52:18 ubuntu2204 dockerd[2719]: time="2022-08-28T05:52:18.620267088Z" level=info msg="Default bridge (docker0) is assigned with an >
Aug 28 05:52:18 ubuntu2204 dockerd[2719]: time="2022-08-28T05:52:18.713742709Z" level=info msg="Loading containers: done."
Aug 28 05:52:18 ubuntu2204 dockerd[2719]: time="2022-08-28T05:52:18.744925054Z" level=info msg="Docker daemon" commit=a89b842 graphdriver(s)=>
Aug 28 05:52:18 ubuntu2204 dockerd[2719]: time="2022-08-28T05:52:18.745338168Z" level=info msg="Daemon has completed initialization"
Aug 28 05:52:18 ubuntu2204 systemd[1]: Started Docker Application Container Engine.
Aug 28 05:52:18 ubuntu2204 dockerd[2719]: time="2022-08-28T05:52:18.805663866Z" level=info msg="API listen on /run/docker.sock"
安装 Docker Compose
你还需要在系统上安装 Docker Compose。可以使用以下命令下载并安装:
curl -sL "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
接下来,使用以下命令为下载的二进制文件设置执行权限:
chmod +x /usr/local/bin/docker-compose
接下来,使用以下命令检查 Docker Compose 版本:
docker-compose --version
你将看到以下输出:
docker-compose version 1.29.2, build 5becea4c
为 Bitwarden 创建用户
以专用用户身份运行 Bitwarden 是一个不错的做法。你可以使用以下命令创建一个新用户,并将其加入 sudo 和 docker 组:
useradd -G docker,sudo -s /bin/bash -m -d /opt/bitwarden bitwarden
接下来,使用以下命令设置用户密码:
passwd bitwarden
你应该会看到以下输出:
New password: Retype new password: passwd: password updated successfully
接下来,更改 bitwarden 目录的所有权:
chown -R bitwarden: /opt/bitwarden
在 Ubuntu 22.04 上安装 Bitwarden 密码管理器
首先,访问 Bitwarden 托管页面,获取 Bitwarden 安装密钥和 id,如下所示:

接下来,切换到 Bitwarden 用户,并使用以下命令下载 Bitwarden 安装脚本:
su - bitwarden
curl -Lso bitwarden.sh https://go.btwrdn.co/bw-sh
接下来,为下载的脚本设置执行权限:
chmod +x bitwarden.sh
接下来,使用以下命令安装 Bitwarden 密码管理器:
sudo ./bitwarden.sh install
系统将提示你提供域名或 IP、SSL 信息以及数据库名称,如下所示:
_ _ _ _ | |__ (_) |___ ____ _ _ __ __| | ___ _ __ | '_ \| | __\ \ /\ / / _` | '__/ _` |/ _ \ '_ \ | |_) | | |_ \ V V / (_| | | | (_| | __/ | | | |_.__/|_|\__| \_/\_/ \__,_|_| \__,_|\___|_| |_| Open source password management solutions Copyright 2015-2022, 8bit Solutions LLC https://bitwarden.com, https://github.com/bitwarden =================================================== bitwarden.sh version 2022.8.4 Docker version 20.10.17, build 100c701 docker-compose version 1.29.2, build 5becea4c (!) Enter the domain name for your Bitwarden instance (ex. bitwarden.example.com): 208.117.81.243 (!) Do you want to use Let's Encrypt to generate a free SSL certificate? (y/n): n (!) Enter the database name for your Bitwarden instance (ex. vault): bitwarden
填写所有必要信息并按 Enter 键。随后系统会提示你提供 Bitwarden 安装密钥、id 和 SSL 信息:
2022.8.4: Pulling from bitwarden/setup 1efc276f4ff9: Pull complete e5aeae5c9ad4: Pull complete 9d8b4edc672a: Pull complete 67bb3a123350: Pull complete 4b31f33ff8ee: Pull complete 8302c6d93c2f: Pull complete 64c1ff0e03a3: Pull complete 289e8b648bb1: Pull complete c706fe453135: Pull complete 6b18bfe90415: Pull complete Digest: sha256:257317606bad7b6c06755c81e4f61099b4af8b89829d7a9a2688545b92daa45f Status: Downloaded newer image for bitwarden/setup:2022.8.4 docker.io/bitwarden/setup:2022.8.4 (!) Enter your installation id (get at https://bitwarden.com/host): c1908405-5beb-497f-9f09-aefe00f87c3f (!) Enter your installation key: yQVH9PTcUIPftio0ZM8L (!) Do you have a SSL certificate to use? (y/n): n (!) Do you want to generate a self-signed SSL certificate? (y/n): y
填写所有必要信息并按 Enter 键。Bitwarden 安装完成后,你应该会看到以下输出:
Generating key for IdentityServer. Generating a RSA private key .........................++++ .++++ writing new private key to 'identity.key' ----- !!!!!!!!!! WARNING !!!!!!!!!! You are not using a SSL certificate. Bitwarden requires HTTPS to operate. You must front your installation with a HTTPS proxy or the web vault (and other Bitwarden apps) will not work properly. Building nginx config. Building docker environment files. Building docker environment override files. Building FIDO U2F app id. Building docker-compose.yml. Installation complete If you need to make additional configuration changes, you can modify the settings in `./bwdata/config.yml` and then run: `./bitwarden.sh rebuild` or `./bitwarden.sh update` Next steps, run: `./bitwarden.sh start`
现在,使用以下命令启动 Bitwarden 服务:
sudo ./bitwarden.sh start
你应该会得到以下输出:
bitwarden.sh version 2022.8.4 Docker version 20.10.17, build 100c701 docker-compose version 1.29.2, build 5becea4c Pulling mssql ... done Pulling web ... done Pulling attachments ... done Pulling api ... done Pulling identity ... done Pulling sso ... done Pulling admin ... done Pulling icons ... done Pulling notifications ... done Pulling events ... done Pulling nginx ... done Creating directory /opt/bitwarden/bwdata/core Creating directory /opt/bitwarden/bwdata/core/attachments Creating directory /opt/bitwarden/bwdata/logs Creating directory /opt/bitwarden/bwdata/logs/admin Creating directory /opt/bitwarden/bwdata/logs/api Creating directory /opt/bitwarden/bwdata/logs/events Creating directory /opt/bitwarden/bwdata/logs/icons Creating directory /opt/bitwarden/bwdata/logs/identity Creating directory /opt/bitwarden/bwdata/logs/mssql Creating directory /opt/bitwarden/bwdata/logs/nginx Creating directory /opt/bitwarden/bwdata/logs/notifications Creating directory /opt/bitwarden/bwdata/logs/sso Creating directory /opt/bitwarden/bwdata/logs/portal Creating directory /opt/bitwarden/bwdata/mssql/backups Creating directory /opt/bitwarden/bwdata/mssql/data Creating network "docker_default" with the default driver Creating network "docker_public" with the default driver Creating bitwarden-notifications ... done Creating bitwarden-events ... done Creating bitwarden-icons ... done Creating bitwarden-mssql ... done Creating bitwarden-attachments ... done Creating bitwarden-web ... done Creating bitwarden-sso ... done Creating bitwarden-identity ... done Creating bitwarden-api ... done Creating bitwarden-admin ... done Creating bitwarden-nginx ... done 2022.8.4: Pulling from bitwarden/setup Digest: sha256:257317606bad7b6c06755c81e4f61099b4af8b89829d7a9a2688545b92daa45f Status: Image is up to date for bitwarden/setup:2022.8.4 docker.io/bitwarden/setup:2022.8.4 Bitwarden is up and running! =================================================== visit http://bitwarden.example.com to update, run `./bitwarden.sh updateself` and then `./bitwarden.sh update`
你可以使用以下命令查看所有已下载的 docker 镜像:
sudo docker images
你将看到以下输出:
REPOSITORY TAG IMAGE ID CREATED SIZE bitwarden/mssql 2022.8.4 0fde97fd6c2b 11 days ago 1.4GB bitwarden/setup 2022.8.4 c3f86466c311 11 days ago 271MB bitwarden/notifications 2022.8.4 ad800e29d1bf 11 days ago 286MB bitwarden/identity 2022.8.4 39342ec67118 11 days ago 284MB bitwarden/nginx 2022.8.4 a9e4cdb98e3d 11 days ago 144MB bitwarden/icons 2022.8.4 e52e97fcc4c1 11 days ago 285MB bitwarden/admin 2022.8.4 25fe354a8fa2 11 days ago 346MB bitwarden/sso 2022.8.4 345ee4d3d544 11 days ago 289MB bitwarden/events 2022.8.4 012f3c8dc079 11 days ago 284MB bitwarden/api 2022.8.4 f780a0e0bfbf 11 days ago 289MB bitwarden/attachments 2022.8.4 8b08874c96fc 11 days ago 214MB bitwarden/web 2022.8.1 1ac4e585d2dd 2 weeks ago 247MB
要查看所有正在运行的容器,请运行以下命令:
sudo docker ps
你应该会看到以下输出:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9af240bb8845 bitwarden/nginx:2022.8.4 "/entrypoint.sh" 33 seconds ago Up 28 seconds (health: starting) 80/tcp, 0.0.0.0:80->8080/tcp, :::80->8080/tcp, 0.0.0.0:443->8443/tcp, :::443->8443/tcp bitwarden-nginx 4758bb5d8c6c bitwarden/admin:2022.8.4 "/entrypoint.sh" 39 seconds ago Up 33 seconds (health: starting) 5000/tcp bitwarden-admin 2814dd1eddd2 bitwarden/identity:2022.8.4 "/entrypoint.sh" 45 seconds ago Up 35 seconds (healthy) 5000/tcp bitwarden-identity 22fa6c748d4f bitwarden/sso:2022.8.4 "/entrypoint.sh" 45 seconds ago Up 34 seconds (health: starting) 5000/tcp bitwarden-sso 9906ace7ea69 bitwarden/api:2022.8.4 "/entrypoint.sh" 45 seconds ago Up 34 seconds (healthy) 5000/tcp bitwarden-api 1d1f10c10667 bitwarden/mssql:2022.8.4 "/entrypoint.sh" 45 seconds ago Up 39 seconds (health: starting) bitwarden-mssql f7ab34d501cc bitwarden/attachments:2022.8.4 "/entrypoint.sh" 45 seconds ago Up 37 seconds (healthy) bitwarden-attachments 6646bf077ba8 bitwarden/web:2022.8.1 "/entrypoint.sh" 45 seconds ago Up 39 seconds (healthy) bitwarden-web e73076475cc7 bitwarden/icons:2022.8.4 "/entrypoint.sh" 45 seconds ago Up 35 seconds (health: starting) 5000/tcp bitwarden-icons 535f2f7599c1 bitwarden/events:2022.8.4 "/entrypoint.sh" 45 seconds ago Up 35 seconds (healthy) 5000/tcp bitwarden-events 7a489f258459 bitwarden/notifications:2022.8.4 "/entrypoint.sh" 45 seconds ago Up 34 seconds (healthy) 5000/tcp bitwarden-notifications
访问 Bitwarden Web 界面
至此,Bitwarden 密码管理器已安装并配置完成。现在你可以通过 URL https://your-server-ip 访问其 Web UI。你应该会看到 Bitwarden 登录页面:

点击 Create Account 按钮。你应该会看到以下页面:

填写你的邮箱地址、主密码,然后点击 Create Account 按钮。账户创建完成后,你将被重定向到 Bitwarden 登录页面:

填写你的邮箱地址、密码,然后点击 Log in 按钮。你应该会在以下页面看到 Bitwarden 仪表板:

结论
恭喜!你已在 Ubuntu 22.04 上使用 Docker 成功安装 Bitwarden 密码管理器。现在你可以添加密码,并在多台设备之间共享。如有任何问题,欢迎随时向我提问。