Apache Guacamole 是一个免费的开源远程桌面网关,允许您使用不同的协议(例如 SSH、RDP 和 VNC)远程连接到您的计算机/服务器。 Apache Guacamole 由 Apache Software Foundation 维护,并获得 Apache License 2.0 许可。

Apache Guacamole 是一个无客户端远程桌面网关。您可以随时随地仅使用 Web 浏览器访问 Apache Guacamole。如果您有多个具有不同协议的远程操作系统,例如具有 RDP 的 Windows 和具有 VNC 和 SSH 的 Linux 系统,建议使用 Apache Guacamole。

安装 Docker

安装 Docker 和 Docker compose 后,接下来您将开始为 Apache Guacamole 部署创建项目目录

设置项目目录

首先,通过运行以下命令确保您已以非 root 用户身份登录。

su - alice

创建一个新的项目目录“~/guacamole-server”并将工作目录移入其中。

mkdir -p guacamole-server; cd guacamole-server/

然后,在“~/guacamole-server”目录中创建一个新目录“init”和“docker-compose.yml” ' 文件。

mkdir -p init
touch docker-compose.yml

接下来,运行以下“docker pull”命令下载 Apache Guacamole 安装所需的 Docker 映像。您将下载三个不同的映像,guacd 作为代理管理器,guacamole 作为 Apache Guacamole 的前端,以及 postgres:13将用作 Apache Guacamole 容器的数据库后端。

docker pull guacamole/guacd
docker pull guacamole/guacamole
docker pull postgres:13

下载 guacd 映像。

下载Guacamole镜像。

下载 PostgreSQL 13 镜像。

下载必要的 Docker 镜像后,执行以下命令来运行新的Guacamole容器并运行“initdb.sh”脚本来为您的部署生成数据库架构。这样,您将生成一个Guacamole数据库架构“init/initdb.sql”

docker run --rm guacamole/guacamole /opt/guacamole/bin/initdb.sh --postgres > init/initdb.sql

如果是windows平台则执行

docker run --rm guacamole/guacamole /opt/guacamole/bin/initdb.sh --postgresql > D:dockerguacamoleinitinitdb.sql

通过下面的 cat 命令验证Guacamole数据库架构的内容。

cat init/initdb.sql

输出 :

设置 docker-compose.yml

现在已经下载了必要的 Docker 镜像,您可以开始配置“docker-compose.yml”脚本并设置 Apache Guacamole 安装。

首先使用以下 nano 编辑器命令打开配置文件“docker-compose.yml”。

nano docker-compose.yml

将以下行添加到文件中。

services:
  guacd:
    container_name: guac_guacd
    image: guacamole/guacd:latest
    networks:
      - guacnet
    restart: always
 
  postgres:
    container_name: guac_postgres
    environment:
      PGDATA: /var/lib/postgresql/data/guacamole
      POSTGRES_DB: guacamole_db
      POSTGRES_PASSWORD: 'you password'
      POSTGRES_USER: guacamole_user
    image: postgres:13
    networks:
      - guacnet
    restart: always
    volumes:
      - /D/docker/guacamole/init:/docker-entrypoint-initdb.d:ro
      - /D/docker/guacamole/data:/var/lib/postgresql/data:rw
 
  guacamole:
    container_name: guac_guacamole
    depends_on:
      - guacd
      - postgres
    environment:
      GUACD_HOSTNAME: guacd
      POSTGRES_DATABASE: guacamole_db
      POSTGRES_HOSTNAME: postgres
      POSTGRES_PASSWORD: 'you password'
      POSTGRES_USER: guacamole_user
    image: guacamole/guacamole:latest
    links:
      - guacd
    networks:
      - guacnet
    ports:
      - 8080:8080
    restart: always

networks:
  guacnet:
    driver: bridge

完成后保存并关闭文件“docker-compose.yml”。

使用此“docker-compose.yml”脚本,您将创建三个容器/服务,如下所示:

  • guacd - Apache Guacamole 的主要组件,用于代理多种协议,例如 SSH、RDP、VNC 等。
  • postgres - Apache Guacamole 安装的数据库后端。您的数据将存储在该容器中。
  • guacamole - 连接到 PostgreSQL 和 guacd 服务的 Apache Guacamole Web 应用程序。该容器将在您的主机上公开端口 8080

启动 Apache Guacamole

开始之前,请确保您位于“guacamole-server”项目目录中。然后,运行以下“docker compose”命令来创建并启动 Apache Guacamole 部署。

docker compose up -d

您应该看到如下输出 - 创建并启动了 3 个不同的容器 guac_postgres、guac_guacd 和 guac_guacamole

打开您的网络浏览器并访问您的服务器 IP 地址和端口 8080(即:http://192.168.5.100:8080/guacamole/)。您将看到 Apache Guacamole 登录页面。

通过默认用户“guacadmin”和密码“guacadmin”登录。然后按登录确认。

设置 Nginx 作为反向代理

Nginx 服务器配置

server {
	listen 80;
	server_name guacamole.hwdomain.io;
	root /var/www/html;

	index index.html index.htm index.nginx-debian.html;

	access_log  /var/log/nginx/guac_access.log;
	error_log  /var/log/nginx/guac_error.log;

	location / {
		proxy_pass http://127.0.0.1:8080/guacamole/;
		proxy_buffering off;
		proxy_http_version 1.1;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection $http_connection;
		proxy_cookie_path /guacamole/ /;
	}
}

 

开启二步验证和获取客户端真实IP,docker-compose.yml中加入

      TOTP_ENABLED: true
      REMOTE_IP_VALVE_ENABLED: true

Apache Guacamole 的基本用法

在这一步中,您将学习 Apache Guacamole 的基本用法。您将删除默认的 guacadmin 用户以保护您的部署,为 Apache Guacamole 设置新的管理员用户,设置连接组,最后设置新的 SSH 连接。

最后,您还将通过 Apache Guacamole 连接到 SSH 服务器来验证新连接。

创建新用户

单击右上角的“guacadmin”菜单,然后选择“设置”。

选择“用户”选项卡,您应该会看到默认的“guacadmin”用户。单击“新用户”按钮创建新的 Apache Guacamole 用户。

输入将用于登录的详细用户名,然后输入密码并重复。

在“个人资料”部分,输入用户详细信息,例如全名、电子邮件地址和组织名称。

在“权限”部分,选择所有选项以使该用户成为 Apache Guacamole 安装的管理员。

单击保存确认并创建新用户。然后,从默认的“guacadmin”用户注销。

接下来,使用新用户登录并验证用户配置。

如果成功,您应该会看到 Apache Guacamole 用户仪表板。

现在点击您的用户并选择“设置”。然后单击“用户”选项卡以验证 Apache Guacamole 上的用户列表。您应该看到新用户已创建。

单击默认用户“guacadmin”以获取有关默认用户的详细信息。滚动到底部页面并单击“删除”按钮以删除默认的“guacadmin”用户。

再次点击删除进行确认。

删除默认的“guacadmin”用户后,Apache Guacamole 上唯一剩余的用户就是您的新用户。

现在,您已经在 Apache Guacamole 上创建了一个新的管理员用户,并删除了默认的“guacadmin”用户。删除默认用户“guacadmin”将减轻密码猜测攻击。

创建新连接

确保您已进入 Apache Guacamole“设置”页面。

选择“连接”选项卡,然后单击“新建组”按钮创建新的连接组。

输入群组名称和位置,然后选择类型。在此示例中,您将创建一个新组“SSH-SERVER”。您还可以在“并发限制”部分中为此组中的每个连接设置连接限制。

单击保存进行确认。

现在您应该在连接列表中找到组“SSH-SERVER”。

接下来,单击“新建连接”按钮在 Apache Guacamole 上创建新连接。

输入连接名称,选择默认位置,然后选择该连接的协议。在此示例中,您将创建一个可在“SSH-SERVER”组中使用的SSH连接“Test SSH”。

在“参数”部分,输入主机或 IP 地址、端口、用户名、密码和 SSH 密钥(启用时)的详细信息。

滚动到底部页面并单击保存进行确认。

这样,您现在应该在“SSH-SERVER”组上获得可用的新连接“Test SSH”。

要连接到新的“测试 SSH”连接,请返回到 Apache Guacamole home用户仪表板,您应该会看到连接列表。

单击“测试 SSH”连接进行连接。

如果您未在详细信息连接上提供密码,系统将提示您输入 SSH 服务器的密码。

到这里,您已经创建了一个新用户,删除了默认用户 guacadmin,设置了一个连接组,并在 Apache Guacamole 上创建了一个连接。

 
参考:https://guacamole.incubator.apache.org/doc/gug/guacamole-docker.html

参与评论