# VNC and AFK Setup for Linux 本筆記用於記錄如何在 Linux 系統上設置 VNC server,以利其他電腦遠端操縱,且無須安裝如 `xfce`、`lxde` 等桌面環境,只須使用輕量的`fluxbox` (x-window-manager) 。 同時,使用 `chromium-browser` 掛載 Autosurf、Swash,在 `docker` 容器中運行 TraffMonetizer 以及 Peer2Profit。 使用的 SSH 連線終端為 Tabby。 > 概要 > * 安裝必要套件 `sudo apt install -y tightvncserver chromium-browser xdg-utils autocutsel fluxbox` > * 修改 `/home/username/.vnc/xstartup` > * Tabby port forwarding 或是使用 ssh -L > * VNC viewer 連線測試 > * `crontab -e` 自動刪除 VNC server log > * 設置虛擬記憶體 > * 設定各掛機程式 ## VNC Server Installation and Configuration 首先,安裝 VNC server,這裡使用的是 `tightvncserver`。 `$ sudo apt install tightvncserver` 開啟一個 VNC session,輸入 `$ vncserver`,第一次開啟需要設定 VNC 連線用的密碼,注意密碼最多八個字元,view-only 選項輸入 n。 ``` $ vncserver You will require a password to access your desktops. Password: Verify: Would you like to enter a view-only password (y/n)? n xauth: file /home/ubuntu/.Xauthority does not exist New 'X' desktop is xxx:1 Creating default startup script /home/ubuntu/.vnc/xstartup Starting applications specified in /home/ubuntu/.vnc/xstartup Log file is /home/ubuntu/.vnc/xxx:1.log ```` 輸入 `$ cat /home/ubuntu/.vnc/xxx:1.log` 查看該 VNC session 的 log。 ``` $ cat /home/ubuntu/.vnc/xxx:1.log 15/07/22 07:56:10 Xvnc version TightVNC-1.3.10 15/07/22 07:56:10 Copyright (C) 2000-2009 TightVNC Group 15/07/22 07:56:10 Copyright (C) 1999 AT&T Laboratories Cambridge 15/07/22 07:56:10 All Rights Reserved. 15/07/22 07:56:10 See http://www.tightvnc.com/ for information on TightVNC 15/07/22 07:56:10 Desktop name 'X' (xxx:1) 15/07/22 07:56:10 Protocol versions supported: 3.3, 3.7, 3.8, 3.7t, 3.8t 15/07/22 07:56:10 Listening for VNC connections on TCP port 5901 Font directory '/usr/share/fonts/X11/Type1/' not found - ignoring Font directory '/usr/share/fonts/X11/75dpi/' not found - ignoring Font directory '/usr/share/fonts/X11/100dpi/' not found - ignoring xrdb: No such file or directory xrdb: can't open file '/home/ubuntu/.Xresources' ``` 輸入 `$ vncserver -kill :1`,中止該 VNC session。 ``` $ vncserver -kill :1 Killing Xtightvnc process ID 24112 ``` 接下來必須在 Tabby 的 SSH profile 中設置對應的 Port Forwarding。 ![](https://i.imgur.com/2saVSu8.png) ![](https://i.imgur.com/52x3RSJ.png) 本機的 port 為之後在 VNC viewer 中連線所使用的 port,而遠端(右方)的 port 為 VNC session 的 port ( 5900 + ID )。比如說預設開啟的 VNC server 的 ID 是 :1,那外部要連線進來的 port 就是 5900 + 1 = 5901,VNC viewer 連線所使用的 IP 就為 localhost:5903 ( port forwaring 中設置的本機端)。 之後將該 Tabby session 關掉重開,應會看到以下內容。 ``` SSH Connecting to 141.xxx.xxx.xxx SSH Host key fingerprint: SSH ecdsa-sha2-nistp256 ... SSH Loading private key: file://xxx SSH -> Forwarded (local) 127.0.0.1:5903 → (remote) 127.0.0.1:5901 ``` Forwarded (local) 127.0.0.1:5903 → (remote) 127.0.0.1:5901,就代表成功設置 port forwarding 了。 這時開啟一個 VNC server session 並測試連線。 `$ vncserver` 在 VNC viewer 中,輸入設定好的 localhost:5903 ( 按照先前設定好的數字 port ),點擊 Continue,輸入 VNC server 的密碼,若沒有安裝任何桌面環境或是遠端桌面用的套件,應會看到 `Xsession: unable to start X session... `的錯誤訊息,先關閉視窗,回到 Tabby 中的 SSH 終端。 ![](https://i.imgur.com/rANonvt.png) ![](https://i.imgur.com/dKT2R90.png) 安裝 xrdp,並重啟 VNC server session,再使用 VNC viewer 連線就可以看到終端的畫面了。 `$ sudo apt install xrdp` `$ vncserver -kill :1` `$ vncserver` ![](https://i.imgur.com/Mu68kbs.png) 接下來設定 `xstartup` ,輸入 `$ sudo nano /home/ubuntu/.vnc/xstartup`。 原內容: ```bash #!/bin/sh xrdb "$HOME/.Xresources" xsetroot -solid grey #x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & #x-window-manager & # Fix to make GNOME work export XKL_XMODMAP_DISABLE=1 /etc/X11/Xsession ``` 改為以下: ```bash #!/bin/sh xrdb "$HOME/.Xresources" xsetroot -solid grey xhost + # disable access control autocutsel -fork # copy/paste in VNC viewer #x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & x-window-manager & # open x-window-manager # Fix to make GNOME work export XKL_XMODMAP_DISABLE=1 /etc/X11/Xsession & chromium-browser --incognito <url> & # open chromium-browser in inconito mode and open the specific url ``` `<url>` 改成要自動開啟的網頁。 這樣 VNC server 開啟後就會自動開啟 `chromium-browser`。 至此,基本的 VNC server 已設置完成,接下來就可以著手安裝瀏覽器了。 ## Cromium-browser Installation and Cofiguration 首先,安裝 `chromium-browser`、`xdg-utils`、`autocutsel`(VNC 複製貼上用)以及 `fluxbox`(x-window-manager)。 `$ sudo apt install chromium-browser xdg-utils autocutsel fluxbox` 之後打開一個 VNC server session `$ vncserver` 並用 VNC viewer 連線,應該就能看到 `chromium`,且有簡單的視窗管理器可以使用,效果如下。 ![](https://i.imgur.com/xHTQfUT.png) ## Crontab `$ crontab -e` 加入以下內容,每小時清除 VNC log 並重啟 `chromium-browser`。 ``` 0 * * * * rm -rf /home/ubuntu/.vnc/*.log 0 * * * * killall -9 chrome 1 * * * * export DISPLAY=:1;chromium-browser --incognito https://www.alexamaster.net/ads/autosurf/179449 ``` ## Virtual Memory -- Swap ### 虛擬記憶體設置。 `$ htop` 查詢目前資源用量。 `swapon -s` 列出 swap 檔案。 `df -h` 查詢各磁區大小及用量。 新增 `swap file`,輸入以下。 ``` $ sudo fallocate -l 2G /swapfile $ sudo chmod 600 /swapfile $ sudo mkswap /swapfile $ sudo swapon /swapfile ``` 若出現 ``` fallocate: fallocate failed: Text file busy ``` 則需先暫停分頁檔的使用:`$ sudo swapoff -a`。 接著要將分頁檔設定為開機啟用。 `$ sudo nano /etc/fstab` 加入以下內容並保存即可。 ``` /swapfile swap swap defaults 0 0 ``` ## AFK Setup ### Alexamaster ### Swash ### Traffmonetizer ### Peer2Profit