本教程适用于以下操作系统版本

  • CentOS 8
  • CentOS 7

本页内容

  • 先决条件
  • 安装 LEMP 服务器
  • 安装 Composer
  • 创建数据库
  • 安装并配置 Passbolt
  • 为 Passbolt 配置 Nginx
  • 使用 Let's Encrypt SSL 保护 Passbolt
  • 为 Passbolt 注册用户
  • 配置防火墙
  • 访问 Passbolt Web 界面
  • 总结

Passbolt 是一款开源密码管理器,可让你安全地存储和共享密码。它专为中小型企业设计,用于在团队成员之间存储和共享登录凭据。它是自托管的,并提供社区版和订阅版两种版本。

在本教程中,我们将向你展示如何在 CentOS 8 上使用 Nginx 和 Let's Encrypt SSL 安装 Passbolt 密码管理器。

先决条件

  • 一台运行 CentOS 8 的服务器。
  • 一个指向你服务器 IP 的有效域名。
  • 你的服务器上已配置 root 密码。

安装 LEMP 服务器

首先,使用以下命令安装 Nginx 和 MariaDB 数据库服务器:

dnf install nginx mariadb-server -y

接下来,你需要在服务器中安装最新版本的 PHP 及其他所需的 PHP 扩展。默认情况下,CentOS 默认仓库中没有最新版本的 PHP。因此你需要向系统添加 EPEL 和 REMI 仓库。

你可以使用以下命令添加这两个仓库:

dnf install epel-release -y
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

接下来,使用以下命令禁用默认的 PHP 仓库并启用 REMI 仓库:

dnf module reset php
dnf module enable php:remi-7.4

接下来,运行以下命令安装 PHP 及其他所需的依赖:

dnf install php php-fpm php-intl php-gd php-mysqli php-json php-pear php-devel php-mbstring php-fpm git make unzip -y

安装完所有软件包后,你需要编辑 PHP-FPM 配置文件,并将用户和组更改为 Nginx。

nano /etc/php-fpm.d/www.conf

更改以下行:

user = nginx
group = nginx

保存并关闭文件,然后更改会话目录的所有权:

chgrp nginx /var/lib/php/session

接下来,使用以下命令启动 Nginx、MariaDB 和 PHP-FPM 服务,并设置它们在系统重启时自动启动:

systemctl start mariadb nginx php-fpm
systemctl enable mariadb nginx php-fpm

接下来,你需要在系统中安装 GNUPG 扩展。你可以通过运行以下命令来安装:

dnf config-manager --set-enabled powertools
dnf install gpgme-devel
pecl install gnupg
echo "extension=gnupg.so" > /etc/php.d/gnupg.ini

接下来,重启 PHP-FPM 服务以应用更改:

systemctl restart php-fpm

安装 Composer

Composer 是 PHP 的依赖管理器。你需要在系统中安装它。

首先,使用以下命令下载 Composer 安装文件:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

接下来,使用以下命令安装 Composer:

php composer-setup.php --install-dir=/usr/local/bin --filename=composer

你应该会看到如下输出:

All settings correct for using Composer
Downloading...

Composer (version 2.0.11) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

接下来,使用以下命令验证 Composer 版本:

composer -V

你应该会看到如下输出:

Composer version 2.0.11 2021-02-24 14:57:23

创建数据库

接下来,你需要为 Passbolt 创建数据库和用户。

首先,使用以下命令连接 MariaDB:

mysql

连接后,使用以下命令创建数据库和用户:

MariaDB [(none)]> CREATE DATABASE passbolt DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
MariaDB [(none)]> GRANT ALL ON passbolt.* TO 'passbolt'@'localhost' IDENTIFIED BY 'password';

接下来,使用以下命令刷新权限并退出 MariaDB:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

完成后,你可以继续执行下一步。

安装并配置 Passbolt

首先,切换到 Nginx Web 根目录,并使用以下命令下载最新版本的 Passbolt:

cd /var/www
git clone https://github.com/passbolt/passbolt_api.git passbolt

下载完成后,切换到 passbolt 目录,并使用以下命令安装所有必需的依赖:

cd passbolt
composer install --no-dev

接下来,你需要安装 haveged 以生成 GPG 密钥。首先,使用以下命令安装 haveged:

dnf install haveged

接下来,使用以下命令启动 haveged 服务:systemctl start haveged

接下来,使用以下命令生成 GPG 密钥:

gpg --full-generate-key

仔细回答所有问题。当要求设置密码时,将密码字段留空:

gpg (GnuPG) 2.2.9; Copyright (C) 2018 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

gpg: directory '/root/.gnupg' created
gpg: keybox '/root/.gnupg/pubring.kbx' created
Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
Your selection? 
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
      
  = key expires in n days
      
w = key expires in n weeks
      
m = key expires in n months
      
y = key expires in n years
Key is valid for? (0) 
Key does not expire at all
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: Hitesh
Email address: 
[email protected]

Comment: Welcome
You selected this USER-ID:
    "Hitesh (Welcome) <
[email protected]
>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key 1A0448FECA43E1F9 marked as ultimately trusted
gpg: directory '/root/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/root/.gnupg/openpgp-revocs.d/40733A5076D11E86EF2FE5B51A0448FECA43E1F9.rev'
public and secret key created and signed.

pub   rsa2048 2021-03-12 [SC]
      40733A5076D11E86EF2FE5B51A0448FECA43E1F9
uid                      Hitesh (Welcome) <
[email protected]
>
sub   rsa2048 2021-03-12 [E]

注意:请记住上面生成的密钥。

接下来,使用以下命令将密钥导出到 serverkey_private.asc 和 serverkey.asc 文件:

gpg --armor --export-secret-keys 
[email protected]
 > /var/www/passbolt/config/gpg/serverkey_private.asc
gpg --armor --export 
[email protected]
 > /var/www/passbolt/config/gpg/serverkey.asc

接下来,为 passbolt 目录设置适当的所有权:

chown -R nginx:nginx /var/www/passbolt

接下来,使用以下命令初始化 Nginx 密钥环:

sudo su -s /bin/bash -c "gpg --list-keys" nginx

输出:

gpg: directory '/var/lib/nginx/.gnupg' created
gpg: keybox '/var/lib/nginx/.gnupg/pubring.kbx' created
gpg: /var/lib/nginx/.gnupg/trustdb.gpg: trustdb created

接下来,重命名 Passbolt 默认配置文件:

cp config/passbolt.default.php config/passbolt.php

接下来,编辑 passbolt.php 文件并定义你的数据库设置和基础 URL:

nano config/passbolt.php

更改以下行:

        'fullBaseUrl' => 'https://passbolt.linuxbuz.com',
    // Database configuration.
    'Datasources' => [
        'default' => [
            'host' => 'localhost',
            //'port' => 'non_standard_port_number',
            'username' => 'passbolt',
            'password' => 'password',
            'database' => 'passbolt',
            'serverKey' => [
                // Server private key fingerprint.
                'fingerprint' => '40733A5076D11E86EF2FE5B51A0448FECA43E1F9',
                'public' => CONFIG . 'gpg' . DS . 'serverkey.asc',
                'private' => CONFIG . 'gpg' . DS . 'serverkey_private.asc',

保存并关闭文件,然后使用以下命令安装 Passbolt:

cd /var/www/passbolt
sudo su -s /bin/bash -c "./bin/cake passbolt install --no-admin" nginx

你应该会看到如下输出:

All Done. Took 0.9595s

Import the server private key in the keyring
---------------------------------------------------------------
Importing /var/www/passbolt/config/gpg/serverkey_private.asc
Keyring init OK

Passbolt installation success! Enjoy! ?

为 Passbolt 配置 Nginx

接下来,你需要为 Passbolt 创建 Nginx 配置文件。你可以使用以下命令创建:

nano /etc/nginx/conf.d/passbolt.conf

添加以下行:

server {
  listen 80;
  server_name passbolt.linuxbuz.com;
  root /var/www/passbolt;
  
  location / {
    try_files $uri $uri/ /index.php?$args;
    index index.php;
  }
  
  location ~ \.php$ {
    fastcgi_index           index.php;
    fastcgi_pass            unix:/var/run/php-fpm/www.sock;
    fastcgi_split_path_info ^(.+\.php)(.+)$;
    include                 fastcgi_params;
    fastcgi_param           SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param           SERVER_NAME $http_host;
  }
       
  location ~* \.(jpe?g|woff|woff2|ttf|gif|png|bmp|ico|css|js|json|pdf|zip|htm|html|docx?|xlsx?|pptx?|txt|wav|swf|svg|avi|mp\d)$ {
    access_log off;
    log_not_found off;
    try_files $uri /webroot/$uri /index.php?$args;
  }
}

保存并关闭文件,然后检查 Nginx 是否存在语法错误:

nginx -t

输出:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

接下来,重启 Nginx 以应用更改:

systemctl restart nginx

使用 Let's Encrypt SSL 保护 Passbolt

接下来,你需要安装 Certbot 客户端,以便为 Passbolt 安装 Let's Encrypt SSL。你可以使用以下命令安装:

dnf install letsencrypt python3-certbot-nginx

接下来,使用以下命令为你的域名获取并安装 SSL 证书:

certbot --nginx -d passbolt.linuxbuz.com

系统会要求你提供电子邮件地址并接受服务条款:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): 
[email protected]


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Account registered.
Requesting a certificate for passbolt.linuxbuz.com
Performing the following challenges:
http-01 challenge for passbolt.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/passbolt.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/passbolt.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://passbolt.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Subscribe to the EFF mailing list (email: 
[email protected]
).


IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/passbolt.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/passbolt.linuxbuz.com/privkey.pem
   Your certificate will expire on 2021-06-09. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again with the "certonly" option. To non-interactively
   renew *all* of your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

为 Passbolt 注册用户

接下来,你需要为 Passbolt 注册用户。你可以使用以下命令完成:

cd /var/www/passbolt
sudo su -s /bin/bash -c "./bin/cake passbolt register_user -u 
[email protected]
 -f example -l Demo -r admin" nginx

你应该会看到如下输出:

     ____                  __          ____  
    / __ \____  _____ ____/ /_  ____  / / /_ 
   / /_/ / __ `/ ___/ ___/ __ \/ __ \/ / __/ 
  / ____/ /_/ (__  |__  ) /_/ / /_/ / / /    
 /_/    \__,_/____/____/_.___/\____/_/\__/   

 Open source password manager for teams
---------------------------------------------------------------
User saved successfully.
To start registration follow the link provided in your mailbox or here: 
https://passbolt.linuxbuz.com/setup/install/f81227bc-b0b6-44b5-99a7-6b490a4ba262/5a112de0-6ca4-4e1b-97c8-26453ef3828b

你可以使用上面的链接访问 Passbolt。

配置防火墙

接下来,你需要在防火墙中允许端口 80 和 443。你可以使用以下命令完成:

firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp

现在,重新加载 firewalld 以应用更改:

firewall-cmd --reload

访问 Passbolt Web 界面

现在,打开 Web 浏览器并输入 URL https://passbolt.linuxbuz.com/setup/install/f81227bc-b0b6-44b5-99a7-6b490a4ba262/5a112de0-6ca4-4e1b-97c8-26453ef3828b 。你将被重定向到以下页面:

如何在CentOS 8上安装Passbolt自托管密码管理器

在这里,你需要下载 Passbolt 浏览器扩展,并在安装后刷新页面。你应该会看到以下页面:

如何在CentOS 8上安装Passbolt自托管密码管理器

指定安全密码并点击 Next 按钮。你应该会看到以下页面:

如何在CentOS 8上安装Passbolt自托管密码管理器

选择一种颜色,输入安全令牌并点击 Next 按钮。你将被重定向到以下页面中的 Passbolt 仪表盘:

如何在CentOS 8上安装Passbolt自托管密码管理器

总结

恭喜!你已在 CentOS 8 上使用 Nginx 和 Let's Encrypt SSL 成功安装了 Passbolt 密码管理器。现在你可以在你的组织中部署 Passbolt,并开始在团队成员之间安全地存储和共享登录凭据。