在 Ubuntu 中安裝 Guacamole 用於遠端訪問 Linux/Windows


在當今互聯互通的世界中,遠端訪問 Linux 和 Windows 計算機對於高效的系統管理和故障排除至關重要。Guacamole 是一款開源的無客戶端遠端桌面閘道器,允許您僅使用 Web 瀏覽器從任何地方訪問您的計算機。本文將指導您完成在 Ubuntu 上安裝 Guacamole 的過程,並演示如何遠端訪問 Linux 和 Windows 系統。

先決條件

在開始之前,請確保您已具備以下先決條件:

  • 執行 Ubuntu(版本 18.04 或更高版本)並具有管理員許可權的計算機。

  • 穩定的網際網路連線。

  • 讓我們開始吧!

步驟 1:更新系統軟體包

首先,讓我們透過執行以下命令更新 Ubuntu 計算機上的系統軟體包:

sudo apt update
sudo apt upgrade -y

這些命令將更新您的軟體包列表並升級系統上任何過時的軟體包。

步驟 2:安裝依賴項

Guacamole 需要幾個依賴項才能正常執行。執行以下命令來安裝它們:

sudo apt install -y libcairo2 libjpeg-turbo8 libjpeg-turbo8-dev libpng-dev libossp-uuid-dev libavcodec-dev libavutil-dev libswscale-dev freerdp2-dev libpango1.0-dev libssh2-1-dev libtelnet-dev libvncserver-dev libpulse-dev libssl-dev libvorbis-dev libwebp-dev tomcat9 tomcat9-admin tomcat9-common tomcat9-user

此命令將安裝 Guacamole 正確執行所需的必要庫和工具。

步驟 3:下載並安裝 Guacamole 伺服器

現在,讓我們按照以下步驟下載並安裝 Guacamole 伺服器元件:

示例

使用 wget 下載 Guacamole 伺服器原始碼歸檔檔案:

wget https://downloads.apache.org/guacamole/1.3.0/source/guacamole-server-1.3.0.tar.gz

輸出

--2023-06-29 12:00:00--  https://downloads.apache.org/guacamole/1.3.0/source/guacamole-server-1.3.0.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 207.244.88.140, 40.79.78.1, 88.99.95.219, ...
Connecting to downloads.apache.org (downloads.apache.org)|207.244.88.140|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2483457 (2.4M) [application/x-gzip]
Saving to: ‘guacamole-server-1.3.0.tar.gz’

guacamole-server-1.3.0.tar.gz            100%[====================================================================>]   2.37M  --.-KB/s    in 0.1s

2023-06-29 12:00:00 (23.4 MB/s) - ‘guacamole-server-1.3.0.tar.gz’ saved [2483457/2483457]

解壓縮下載的歸檔檔案:

示例

tar -xzf guacamole-server-1.3.0.tar.gz

輸出

guacamole-server-1.3.0/
guacamole-server-1.3.0/src/
guacamole-server-1.3.0/src/modules/
guacamole-server-1.3.0/src/modules/rdp/
guacamole-server-1.3.0/src/modules/rdp/README
guacamole-server-1.3.0/src/modules/rdp/rdp_settings.c
guacamole-server-1.3.0/src/modules/rdp/rdp_cache.c
guacamole-server-1.3.0/src/modules/rdp/rdp_fs.c
guacamole-server-1.3.0/src/modules/rdp/rdp_cliprdr.c
guacamole-server-1.3.0/src/modules/rdp/rdpdr_messages.c
guacamole-server-1.3.0/src/modules/rdp/rdpdr_fs_messages.c
guacamole-server-1.3.0/src/modules/rdp/rdp_svc.c
guacamole-server-1.3.0/src/modules/rdp/rdpdr_messages.h
...

切換到解壓縮的目錄:

示例

cd guacamole-server-1.3.0

配置構建:

./configure --with-init-dir=/etc/init.d

輸出

checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether UID '1000' is supported by ustar format... yes
checking whether GID '1000' is supported by ustar format... yes
checking how to create a ustar tar archive... gnutar
checking whether make supports nested variables... (cached) yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
...

構建並安裝 Guacamole 伺服器:

示例

make
sudo make install
sudo ldconfig

輸出

...
make[1]: Entering directory '/path/to/package'
make[2]: Entering directory '/path/to/package/src'
/bin/mkdir -p '/usr/local/bin'
/bin/mkdir -p '/usr/local/lib'
/usr/bin/install -c program_name '/usr/local/bin'
/usr/bin/install -c -m 644 libname.so '/usr/local/lib'
/usr/bin/install -c -m 644 header.h '/usr/local/include'
make[2]: Leaving directory '/path/to/package/src'
make[1]: Leaving directory '/path/to/package'

步驟 4:配置 Guacamole

安裝伺服器後,是時候配置 Guacamole 了。以下是如何操作:

複製示例 Guacamole 配置檔案:

sudo cp guacamole-server-1.3.0/guacamole-server/src/main/webapp/WEB-INF/guacamole.properties.example /etc/guacamole/guacamole.properties

使用您選擇的文字編輯器編輯配置檔案。例如:

sudo nano /etc/guacamole/guacamole.properties

在此檔案中,您可以自定義各種設定,例如資料庫連線詳細資訊、身份驗證機制等。編輯完檔案後,請確保儲存更改。

步驟 5:部署 Guacamole Web 應用程式

要在您的 Ubuntu 計算機上部署 Guacamole Web 應用程式,請按照以下步驟操作:

下載 Guacamole Web 應用程式歸檔檔案:

wget https://downloads.apache.org/guacamole/1.3.0/binary/guacamole-1.3.0.war -O guacamole.war

將下載的歸檔檔案移動到 Tomcat webapps 目錄:

sudo mv guacamole.war /var/lib/tomcat9/webapps/guacamole.war

重新啟動 Tomcat 以使更改生效:

sudo systemctl restart tomcat9

步驟 6:訪問 Guacamole Web 介面

此時,Guacamole 已安裝並可以使用。要訪問 Guacamole Web 介面,請開啟您的 Web 瀏覽器並輸入以下 URL:

http://<your-server-ip>:8080/guacamole/

將 <your-server-ip> 替換為您 Ubuntu 計算機的 IP 地址或域名。您應該會看到 Guacamole 登入螢幕。

步驟 7:配置 Guacamole 使用者和連線

要開始使用 Guacamole,您需要配置使用者和連線。以下是如何操作:

開啟 Guacamole 配置檔案:

sudo nano /etc/guacamole/guacamole.properties

取消註釋 # auth-provider: net.sourceforge.guacamole.net.basic.BasicFileAuthenticationProvider 行並儲存檔案。

為使用者身份驗證建立一個新檔案:

sudo nano /etc/guacamole/user-mapping.xml

將使用者和連線配置新增到 user-mapping.xml 檔案中。以下是 Linux 計算機的示例配置:

<?xml version="1.0" encoding="UTF-8"?>
<user-mapping>
   <authorize username="user1" password="password1">
      <connection name="Linux Server">
         <protocol>ssh</protocol>
         <param name="hostname">192.168.1.100</param>
         <param name="port">22</param>
         <param name="username">remoteuser</param>
      </connection>
   </authorize>
</user-mapping>

在此示例中,配置了名為“user1”且密碼為“password1”的使用者以透過 SSH 連線到 Linux 伺服器。

儲存 user-mapping.xml 檔案。

重新啟動 Tomcat 以應用配置更改:

sudo systemctl restart tomcat9

結論

恭喜!您已成功在 Guacamole 中配置了使用者和連線,使您可以輕鬆訪問遠端 Linux 和 Windows 計算機。Guacamole 提供了一種方便且安全的方式,可以透過 Web 瀏覽器遠端管理您的系統。

請記住定期更新和維護您的 Guacamole 安裝,以利用最新的功能和安全補丁。

享受 Guacamole 帶來的遠端訪問便利!

更新於: 2023年7月17日

3K+ 閱讀量

開啟您的 職業生涯

透過完成課程獲得認證

開始學習
廣告