Install vnc on ubuntu18 xfce and set it to start automatically

Install remote desktop for ubuntu18 (xfce desktop, not gnome desktop)

Before introducing the installation of vnc, first recommend the nomachine remote desktop, which is friendly to Linux. Find the installation package of the corresponding system (x86 or arm64, etc.) on the official website, install it in one step, without any configuration, and apply to any desktop. And by default, it starts automatically after booting, and it transmits the real video data of ubuntu instead of opening a new desktop. The frame rate is high and the video quality is good, but the CPU is also high after connection. Raspberry Pi 4b may occupy 30% of the CPU.

I tried tightvncserver and xrdp, and tried to connect to ubuntu with the remote desktop that comes with win10. Unsuccessful and troublesome.

The following introduces the installation of vnc4server, which is a newly opened desktop, with low cpu occupancy, fast connection, smoother in general operation, and a frame by frame comparison card when there is a video animation.

Main reference:

https://blog.csdn.net/m0_37041325/article/details/80516041

https://blog.csdn.net/muslim377287976/article/details/103820434

System: ubuntu16.04

  1. Install Xfce4 desktop environment (please skip it if it is already installed)
    sudo apt-get install xfce4
  2.     Install VNCServer
    sudo apt-get install vnc4server
  3. After the installation is complete, enter the following two items in the terminal (optionally set the resolution)
    vncserver
    vncserver -geometry 1600x900
    Follow the prompts to set the password for logging in to VNC, and then a prompt will appear. The main meaning is that VNCServer generates a new desktop :1and generates a /home/username/.vnc/configuration file in the directory xstartup. At this time, if you connect to the remote desktop directly with VNCView, a blank window will appear, so we need to configure this xstartupfile
  4. Configuration xstartupfile. The xstartupcontent of the modified file is as follows, for the Xfce4 desktop environment.
    #!/bin/sh
    unset SESSION_MANAGER
    unset DBUS_SESSION_BUS_ADDRESS
    startxfce4 &
    
    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey

    After modifying the configuration file, run the following command to end the previous window:1
    $ vncserver -kill :1
    Restart VNCServer afterwards
    vncserver
  5. 配置完成,通过电脑端的VNCView链接该远程主机即可。
    For example, connect to 192.168.31.172:1

Set vnc to start on boot

Now if you want to connect to vnc, you have to connect to ssh first, which is too much trouble. Let's directly set up vnc to start at boot

Create /etc/init.d/vncserver and
enter the following:

#!/bin/sh
### BEGIN INIT INFO
# Provides: tightvncserver
# Required-Start: $syslog $remote_fs $network
# Required-Stop: $syslog $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts VNC Server on system start.
# Description: Starts tight VNC Server. Script written by James Swineson.
### END INIT INFO
# /etc/init.d/vncserver
VNCUSER='ubuntu'
case "$1" in
        start)
        		#以ubuntu用户运行以下指令,如果是别的用户,换成对应的用户名
                su $VNCUSER -c 'vncserver :1 -geometry 1600x900'
                echo "Starting VNC Server for $VNCUSER"
        ;;
        stop)
                su $VNCUSER -c 'vncserver -kill :1'
                echo "TightVNC Server stopped"
        ;;
        *)
                echo "Usage: /etc/init.d/vncserver {start|stop}"
                exit 1
        ;;
esac
exit 0

Then add executable permissions to the file

sudo chmod 755 /etc/init.d/vncserver

Add to boot list

sudo update-rc.d vncserver defaults

If you want to cancel the startup:

sudo update-rc.d -f vncserver remove

The setup is complete.

 

 

 

Guess you like

Origin blog.csdn.net/benchuspx/article/details/112578386