# Remote Desktop 遠端桌面

RDP, VNC, NX Fress, X2Go

# XRDP

##### 安裝

```shell
# Ubuntu 18.04
sudo apt-get install xrdp xfce4
echo xfce4-session >~/.xsession

# 檢查 XRDP 是否已啟動
# 檢查 port 3389 是否開啟
sudo netstat -ltpn

# XRDP 服務啟動/關閉
sudo systemctl stop xrdp-sesman
sudo systemctl start xrdp-sesman
```

> TIP:
> 
> \- 不需設定 vncserver 密碼
> 
> \- 預設 port 是 3389，若要變更，可修改 /etc/xrdp/xrdp.ini

Windows 用戶端登入時

1. 選擇 sesman-Xvnc
2. 輸入 Ubuntu 的系統帳號/密碼

##### FAQ

Q: 在 Ubuntu 13/14 遠端連線後出現空白畫面  
Ans: 這是因為 XRDP 與 Gnome 套件有衝突，解決方法只能將桌面程式改成 XFACE，步驟如下：

```shell
sudo add-apt-repository ppa:xubuntu-dev/xfce-4.10
sudo apt-get update
sudo apt-get install xfce4

echo xfce4-session >~/.xsession
sudo service xrdp restart 
```

##### Tutorials

- [Using Windows to Create and Access a Remote Ubuntu Desktop](https://ideaspot.com.au/blog/windows-remote-ubuntu-desktop/)
- [How to Configure Remote Desktop on Ubuntu Server](https://blog.racknerd.com/how-to-configure-remote-desktop-on-ubuntu-server/)

# VNC

#### Installation

##### Ubuntu 9/11

- [How to Set Up a VNC Server In Ubuntu](https://www.maketecheasier.com/set-up-a-vnc-server-in-ubuntu/)

```
sudo apt-get install ubuntu-desktop --no-install-recommends
sudo apt-get install  vnc4server
```

編輯 .vnc/xstartup

```shell
#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
gnome-session & # support for GNOME
startkde $ #support for KDE
```

##### Lubuntu

編輯 .vnc/xstartup

```
/usr/bin/lxsession -s Lubuntu -e LXDE
```

##### CentOS

CentOS 6：

```
yum groupinstall Desktop
yum install tigervnc tigervnc-server
```

設定 VNC 密碼

```
vncserver
```

編輯 ~/.vnc/xstartup

```
# 移除註解
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
```

設定開機後自動啟動

/etc/sysconfig/vncservers

```
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1280x1024"     #這行可不加
```

```
chkconfig vncserver on
```

CentOS 5：

```
# Install
yum install vnc-server

# Set the password for vnc
vncserver
```

/root/.vnc/xstartup

```
xsetroot -solid grey
vncconfig -iconic &
gnome-session &   # 加這行
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & # 註解這行
#twm & # 註解這行
```

重啟 vncserver

```
vncserver -kill :1
vncserver
```

畫面解析太小

```
vncserver -geometry 1280x960
```

#### KasmVNC

KasmVNC - Linux Web Remote Desktop

- \[GitHub\] [KasmVNC - Modern VNC Server and client, web based and secure](https://github.com/kasmtech/KasmVNC)

#### Learning

- [How to install and access CentOS remote desktop on VPS](https://www.xmodulo.com/centos-remote-desktop-vps.html)
- [How to Access Remote Desktop from Browser Using TightVNC](https://www.tecmint.com/vnc-desktop-access-from-web-browser/)

# NX free edition

官網：[https://www.nomachine.com/download](https://www.nomachine.com/download)

安裝

下載 3 個安裝檔

- nxclient\_3.5.0-7\_i386.deb
- nxnode\_3.5.0-7\_i386.deb
- nxserver\_3.5.0-9\_i386.deb

```
sudo dpkg -i nxclient_3.5.0-7_i386.deb
sudo dpkg -i nxnode_3.5.0-7_i386.deb
sudo dpkg -i nxserver_3.5.0-9_i386.deb
```

Windows 用戶端

下載 NX Client for Windows

# X2Go

特色

- 可多人登入
- 可播放影片
- 資源耗用較少
- 登入使用 SSH 帳號
- NX-based remote desktop solutions

X2Go Server

```shell
sudo apt-add-repository ppa:x2go/stable
sudo apt-get update
sudo apt-get install x2goserver x2goserver-xsession
sudo apt-get install x2gomatebindings
sudo apt-get install xfce4 xfce4-terminal
sudo apt-get install gnome-icon-theme tango-icon-theme
```

X2Go Client

```
sudo apt-add-repository ppa:x2go/stable
sudo apt-get update
sudo apt-get install x2goclient
```

Learning

- [X2Go - everywhere@home](https://wiki.x2go.org/doku.php)
- [How to install X2Goserver on Ubuntu 14.04 as an alternative for VNC](https://www.howtoforge.com/how-to-install-x2goserver-on-ubuntu-14.04-as-vnc-alternative)
- [How to set up remote desktop on Linux VPS using x2go](https://www.xmodulo.com/x2go-remote-desktop-linux.html)

# Guacamole

Apache Guacamole is a clientless remote desktop gateway. It supports standard protocols like VNC, RDP, and SSH.

Home: [https://guacamole.apache.org/](https://guacamole.apache.org/)

- **Access your computers from anywhere**  
    Because the Guacamole client is an HTML5 web application, use of your computers is not tied to any one device or location. As long as you have access to a web browser, you have access to your machines.
- **Keep your desktop in the cloud**  
    Desktops accessed through Guacamole need not physically exist. With both Guacamole and a desktop operating system hosted in the cloud, you can combine the convenience of Guacamole with the resilience and flexibility of cloud computing.
- **Free and open source**  
    Apache Guacamole is and will always be free and open source software. It is licensed under the Apache License, Version 2.0, and is actively maintained by a community of developers that use Guacamole to access their own development environments.  
    We feel this sets us apart from other remote desktop solutions, and gives us a distinct advantage.
- **Built on a well-documented API**  
    Apache Guacamole is built on its own stack of core APIs which are thoroughly documented, including basic tutorials and conceptual overviews in the online manual. These APIs allow Guacamole to be tightly integrated into other applications, whether they be open source or proprietary.

#### Installation

##### With Docker

docker-compose.yml:

```YAML
version: "3"
services:
  guacamole:
    image: jwetzell/guacamole
    container_name: guacamole
    volumes:
      - ./postgres:/config
    ports:
      - 8880:8080
volumes:
  postgres:
    driver: local
```

Login with the default credentials of:

- username: guacadmin
- password: guacadmin

More available extensions:

- auth-ldap - [LDAP Authentication](https://guacamole.apache.org/doc/gug/ldap-auth.html)
- auth-duo - [Duo two-factor authentication](https://guacamole.apache.org/doc/gug/duo-auth.html)
- auth-header - [HTTP header authentication](https://guacamole.apache.org/doc/gug/header-auth.html)
- auth-cas - [CAS Authentication](https://guacamole.apache.org/doc/gug/cas-auth.html)
- auth-openid - [OpenID Connect authentication](https://guacamole.apache.org/doc/gug/openid-auth.html)
- auth-totp - [TOTP two-factor authentication](https://guacamole.apache.org/doc/gug/totp-auth.html)
- auth-quickconnect - [Ad-hoc connections extension](https://guacamole.apache.org/doc/gug/adhoc-connections.html)

Usage:

```shell
docker run \
-p 8080:8080 \
-v </path/to/config>:/config \
-e "EXTENSIONS=auth-ldap,auth-duo" \
jwetzell/guacamole
```

#### Authentications

##### Google two-factor

With docker-compose

```YAML
version: "3"
services:
  guacamole:
...
    environment:
      - EXTENSIONS=auth-totp
...
```

#### SSH

SSH-Key Authentication

```shell
# Generate the private key and public key
# NOTE: -m PEM is required for Guacamole
ssh-keygen -t rsa -b 4096 -f ~/.ssh/root＠guacamole -C "root＠guacamole" -m PEM
```

#### 複製與貼上  


預設環境遠端主機的文字可以複製，然後在本地端作貼上；不過，本地端文字無法複製後在遠端主機作貼上，解決方法如下：

在遠端主機的畫面，按下 Ctrl + Alt + Shift，會彈出 Guacamole 選單，將本地端文字貼在選單裡的 Clipboard，回到遠端主機，直接執行貼上即可。

#### Learning

- [Access Your Computer From Anywhere Via Web Browser using Apache Guacamole](https://ostechnix.com/apache-guacamole-access-computer-anywhere-via-web-browser/)
- [Install and Use Guacamole Remote Desktop on CentOS 8](https://www.howtoforge.com/install-and-use-guacamole-remote-desktop-on-centos-8/)
- \[Video\] [Guacamole Remote Desktop - Open Source, Self Hosted remote access to your machines in the browser!](https://www.youtube.com/watch?v=DGw6P5Lkj-U)
- \[Video\] [Meet Guacamole, Your Remote Access Gateway](https://www.youtube.com/watch?v=LWdxhZyHT_8)
- \[Video\] [Securely Access any PC or VM Remotely using only a Web Browser with Guacamole](https://www.youtube.com/watch?v=TTFB2XEQQUU)
- [nexus-terminal](https://github.com/Heavrnl/nexus-terminal) - 一款現代化、功能豐富的 Web SSH/RDP/VNC 客戶端，致力於提供高度可定制的遠端連接體驗。

Guacamole with Nginx Reverse Proxy

- [https://github.com/antroguy/HomeLab/blob/master/home-lab-setup/guacamole-with-nginx-reverse-proxy.md](https://github.com/antroguy/HomeLab/blob/master/home-lab-setup/guacamole-with-nginx-reverse-proxy.md)
- [如何在 Ubuntu 22.04 上通过 Docker 安装 Apache Guacamole](https://cn.console-linux.com/?p=29548)

# Learning

- [11 Best Tools to Access Remote Linux Desktop](https://www.tecmint.com/best-remote-linux-desktop-sharing-software/)
- [Get Started With Ubuntu Remote Desktop: What is It &amp; How to Use It](https://bytexd.com/ubuntu-remote-desktop/)
- \[GitHub\] [neko - A self hosted virtual browser that runs in docker and uses WebRTC.](https://github.com/m1k1o/neko)
- \[Video\] [Remote Desktop &amp; Access Tools comparison between 4 great open source, self hosted options!](https://www.youtube.com/watch?v=DZ0Ocwga43w)

##### Webtop

Meet [Webtops](https://www.linuxserver.io/blog/2021-05-05-meet-webtops-a-linux-desktop-environment-in-your-browser) A Linux Desktop Environment In Your Browser

- \[Video\] [Run Linux Desktops in your Browser with Docker and Webtops!](https://www.youtube.com/watch?v=bQrtnZ1UrQQ)

##### SPICE (Proxmox VE is required)

The [SPICE](https://www.spice-space.org/index.html) project aims to provide a complete open source solution for remote access to virtual machines in a seamless way so you can play videos, record audio, share usb devices and share folders without complications.

##### Kasm Workspace

[Kasm Workspace Community Edition](https://kasmweb.com/community-edition) - Kasm Workspaces CE is a no-cost version of the Professional/Enterprise container streaming platform for individual users, non-profit organizations, and businesses wanting to test the platform. Workspaces CE has nearly all the same features as the paid versions with community based support.