VNC Server ใช้ vnc4server
1 2 | sudo apt install xfce4 xfce4-goodies xfonts-thai sudo apt install vnc4server |
ก่อนใช้งานครั้งแรกเราต้องสร้างรหัสผ่านสำหรับเชื่อมต่อ VNC Server เสร็จแล้วสั่งให้ VNC Server ทำงานหนึ่งครั้ง
เสร็จแล้วเราจะได้ไฟล์ xstartup ขึ้นมา จากนั้นทำการปิด VNC Server แล้วเข้าไป แก้ไขไฟล์ xstartup ใน ~/.vnc/xstartup
1 2 3 4 5 | vncpasswd vncserver vncserver - kill :1 nano ~/.vnc /xstartup |
1 2 | #!/bin/bash startxfce4 & |
เมื่อทำการแก้ไขค่าเรียบร้อยแล้วให้ทำการ Save แล้วสั่งให้ VNC Server ทำงานอีกครั้ง
พิมพ์ ss -ltn เพื่อตรวจสอบว่ามี Port 5901 เปิดใช้งานอยู่ แสดงว่า VNC Server ทำงานแล้ว
1 2 | vncserver ss -ltn |
ในการใช้คำสั่ง vncserver ปกตินั้นเราจะได้หน้าจอขนาด 800x600 เป็นค่าพื้นฐาน
แต่หากเราต้องการปรับขนาดเองเราสามารถทำได้โดยใส่ Parameter เพิ่มเข้าไปตามนี้
1 2 | # vncserver -depth {8|16|24|32} -geometry {width}x{height} vncserver -depth 24 -geometry 1280x720 |
สร้าง Service ให้ทำงานอัตโนมัติเมื่อเปิดเครื่อง อย่าลืมเปลี่ยน [sarankon] เป็นชื่อ User ของเครื่อง
1 | sudo nano /etc/systemd/system/vncserver @.service |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [Unit] Description=VNC4Server Service After=syslog.target network.target [Service] Type=forking User=sarankon PIDFile= /home/sarankon/ .vnc/%H:%i.pid ExecStartPre=- /usr/bin/vncserver - kill :%i &> /dev/null ExecStart= /usr/bin/vncserver -geometry 1280x720 -depth 24 :%i ExecStop= /usr/bin/vncserver - kill :%i [Install] WantedBy=multi-user.target |
เซฟแล้วทำเรียก daemon-reload แล้วลองเรียกใช้งานผ่าน systemctl เพื่อทดสอบ
เราสามารถสั่ง start เพื่อเรียกใช้งาน หรือ สั่ง enable เพื่อให้เริ่มการทำงานทุกครั้งเมื่อเปิดเครื่อง
1 2 3 4 5 | sudo systemctl daemon-reload sudo systemctl start vncserver@1 sudo systemctl status vncserver@1 sudo systemctl enable vncserver@1 |
การติดตั้ง novnc เพื่อให้ใช้งาน vnc ผ่านทางเว็บเบราเซอร์ได้เลยไม่ต้องลงโปรแกรม VNC Client
1 2 | sudo apt install novnc websockify -D --web= /usr/share/novnc/ 6080 localhost:5901 |
ถ้ามี Certification
1 | websockify -D --web= /usr/share/novnc/ --cert= /etc/ssl/novnc .pem 6080 localhost:5901 |
เสร็จแล้วให้เราเข้าเว็บเบราเซอร์แล้วพิมพ์ Address ของเครื่องตามด้วย Port 6080 เสร็จแล้วกรอกรหัสของรหัสผ่านของ VPN ก็จะสามารถใช้งานได้
ขอบคุณแหล่งข้อมูลอ้างอิง
https://www.youtube.com/watch?v=Ec2PD4WRdew
https://linuxconfig.org/vnc-server-on-ubuntu-18-04-bionic-beaver-linux
ไม่มีความคิดเห็น:
แสดงความคิดเห็น