本教程适用于以下操作系统版本
- Ubuntu 22.04(Jammy Jellyfish)
- Ubuntu 20.04(Focal Fossa)
本页内容
- 先决条件
- 安装 Apache、MariaDB 和 PHP
- 为 sysPass 配置 MariaDB
- 安装 sysPass
- 为 sysPass 配置 Apache
- 访问 sysPass 管理界面
- 在 sysPass 上安装 Let's Encrypt SSL
- 结语
sysPass 是一款免费、开源且基于 PHP 的密码管理工具,用于将你的密码保存在安全的位置。它是基于 Web 的、安全、可靠,并且专为多用户环境而设计。它带有用户友好的 Web 界面,可帮助用户配置 LDAP 认证、邮件、审计、备份、导入/导出等不同选项。sysPass 可通过 Web 应用、移动应用和浏览器扩展进行安装。
在本文中,我们将向你展示如何在 Ubuntu 22.04 上安装 sysPass 密码管理器。
先决条件
- 一台运行 Ubuntu 22.04 的服务器。
- 一个指向你服务器 IP 的有效域名。
- 服务器上已配置 root 密码。
安装 Apache、MariaDB 和 PHP
在开始之前,你需要在服务器上安装 Apache Web 服务器、MariaDB 数据库服务器、PHP 以及其他 PHP 扩展。首先,使用以下命令安装 Apache 和 MariaDB 服务器:
apt-get install apache2 mariadb-server -y
默认情况下,Ubuntu 22.04 自带 PHP 8.1 版本,但 sysPass 不支持 PHP 8.1 版本。因此你需要在服务器上安装 PHP 7.4 版本及其他扩展。
首先,使用以下命令安装所有必需的依赖项:
apt install software-properties-common ca-certificates lsb-release apt-transport-https
接下来,使用以下命令添加 PHP 仓库:
add-apt-repository ppa:ondrej/php
添加 PHP 仓库后,运行以下命令以安装 PHP 7.4 及所有必需的扩展:
apt install libapache2-mod-php7.4 php7.4 php7.4-mysqli php7.4-pdo php7.4 php7.4-cgi php7.4-cli php7.4-common php7.4-gd php7.4-json php7.4-readline php7.4-curl php7.4-intl php7.4-ldap php7.4-xml php7.4-mbstring git -y
所有软件包安装完成后,编辑 php.ini 文件并进行一些修改:
nano /etc/php/7.4/apache2/php.ini
更改以下设置:
post_max_size = 100M upload_max_filesize = 100M max_execution_time = 7200 memory_limit = 512M date.timezone = UTC
完成后保存并关闭文件。接下来,重启 Apache 服务以使配置更改生效:
systemctl restart apache2
为 sysPass 配置 MariaDB
默认情况下,MariaDB 安装并未加固。因此你需要先对其进行加固。你可以使用以下命令进行加固:
mysql_secure_installation
按如下提示回答所有问题,以设置 MariaDB root 密码并加固安装:
Enter current password for root (enter for none): Switch to unix_socket authentication [Y/n] Y Change the root password? [Y/n] Y New password: Re-enter new password: Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y
完成后,使用以下命令登录 MariaDB 交互界面:
mysql -u root -p
系统会要求你提供 MariaDB root 密码。登录后,使用以下命令创建数据库和用户:
MariaDB [(none)]> create database syspassdb;
MariaDB [(none)]> grant all privileges on syspassdb.* to syspassuser@localhost identified by "password";
接下来,使用以下命令刷新权限并退出 MariaDB shell:
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;
至此,你的 MariaDB 数据库和用户已准备好供 sysPass 使用。现在你可以进入下一步。
安装 sysPass
首先,使用以下命令从 Git 仓库下载最新版本的 sysPass:
git clone https://github.com/nuxsmin/sysPass.git
下载 sysPass 后,将下载的目录移动到 Apache Web 根目录:
mv sysPass /var/www/html/syspass
接下来,使用以下命令为 syspass 目录设置正确的属主:
chown -R www-data:www-data /var/www/html/syspass
接下来,为其他目录设置正确的权限:
chmod 750 /var/www/html/syspass/app/{config,backup}
接下来,你需要在系统上安装 Composer。
首先,使用以下命令创建 Composer 安装脚本:
nano /var/www/html/syspass/install-composer.sh
添加以下行:
#!/bin/sh
EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
exit 1
fi
php composer-setup.php --quiet
RESULT=$?
rm composer-setup.php
exit $RESULT
保存并关闭文件,然后使用以下命令运行 Composer 安装脚本:
cd /var/www/html/syspass/
sh install-composer.sh
Composer 安装完成后,运行以下命令安装所有必需的 PHP 依赖项:
php composer.phar install --no-dev
所有依赖项安装完成后,你就可以进入下一步了。
为 sysPass 配置 Apache
接下来,你需要创建一个 Apache 虚拟主机配置文件,以便在 Web 上托管 sysPass。你可以使用以下命令创建它:
nano /etc/apache2/sites-available/syspass.conf
添加以下行:
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/var/www/html/syspass" ServerName syspass.example.com <Directory "/var/www/html/syspass/"> Options MultiViews FollowSymlinks AllowOverride All Order allow,deny Allow from all </Directory> TransferLog /var/log/apache2/syspass_access.log ErrorLog /var/log/apache2/syspass_error.log </VirtualHost>
完成后保存并关闭文件,然后使用以下命令启用 Apache 虚拟主机:
a2ensite syspass
接下来,重启 Apache 服务以使更改生效:
systemctl restart apache2
你也可以使用以下命令查看 Apache 服务的状态:
systemctl status apache2
你应该得到类似以下输出:
? apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor prese>
Active: active (running) since Sun 2022-07-24 04:27:17 UTC; 6s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 62773 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/S>
Main PID: 62777 (apache2)
Tasks: 6 (limit: 2242)
Memory: 14.3M
CPU: 109ms
CGroup: /system.slice/apache2.service
??62777 /usr/sbin/apache2 -k start
??62778 /usr/sbin/apache2 -k start
??62779 /usr/sbin/apache2 -k start
??62780 /usr/sbin/apache2 -k start
??62781 /usr/sbin/apache2 -k start
??62782 /usr/sbin/apache2 -k start
Jul 24 04:27:17 ubuntu systemd[1]: Starting The Apache HTTP Server...
完成后,你可以进入下一步。
访问 sysPass 管理界面
现在,打开你的 Web 浏览器,使用 URL http://syspass.example.com 访问 sysPass 管理界面。你将被重定向到以下页面:


填写管理员用户名、密码、主密码、数据库凭据,选择你的语言和托管模式,然后点击 INSTALL 按钮。安装完成后,你将被重定向到 sysPass 登录页面。

填写管理员用户名、密码,然后点击 > 按钮。你应该在下一页看到 sysPass 仪表盘:

在 sysPass 上安装 Let's Encrypt SSL
使用 Let's Encrypt SSL 来保护你的网站始终是个好主意。首先,你需要安装 Certbot 客户端来安装和管理 SSL。默认情况下,Certbot 软件包已包含在 Ubuntu 22.04 的默认仓库中,因此你可以使用以下命令安装它:
apt-get install python3-certbot-apache -y
Certbot 安装完成后,运行以下命令,使用 Let's Encrypt SSL 保护你的网站:
certbot --apache -d syspass.example.com
系统会要求你提供电子邮件并接受服务条款,如下所示:
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator standalone, Installer None 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 at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: A - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing 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 Plugins selected: Authenticator apache, Installer apache Obtaining a new certificate Performing the following challenges: http-01 challenge for syspass.example.com Enabled Apache rewrite module Waiting for verification... Cleaning up challenges Created an SSL vhost at /etc/apache2/sites-available/syspass-le-ssl.conf Enabled Apache socache_shmcb module Enabled Apache ssl module Deploying Certificate to VirtualHost /etc/apache2/sites-available/syspass-le-ssl.conf Enabling available site: /etc/apache2/sites-available/syspass-le-ssl.conf
接下来,选择是否将 HTTP 流量重定向到 HTTPS,如下所示:
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
输入 2 并按下回车键,为你的网站安装 Let's Encrypt SSL:
Enabled Apache rewrite module Redirecting vhost in /etc/apache2/sites-enabled/syspass.conf to ssl vhost in /etc/apache2/sites-available/syspass-le-ssl.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://syspass.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=syspass.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/syspass.example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/syspass.example.com/privkey.pem Your cert will expire on 2022-10-20. 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
结语
恭喜!你已经成功在 Ubuntu 22.04 上使用 Apache 和 Let's Encrypt SSL 安装了 sysPass 密码管理器。现在你可以探索 sysPass 密码管理器,并开始在生产环境中部署它。