Home > Java > javaTutorial > body text

Starting from Scratch: Detailed Installation and Setup of VNC on Ubuntu

WBOY
Release: 2023-12-29 16:27:33
Original
1377 people have browsed it

Starting from Scratch: Detailed Installation and Setup of VNC on Ubuntu

Start from scratch: Detailed explanation of the installation and setup of VNC on Ubuntu

On the Ubuntu operating system, VNC (Virtual Network Computing) is a remote desktop protocol that can Achieve remote access and control of Ubuntu desktop through network connection. This article will detail the steps to install and set up VNC on Ubuntu, including specific code examples.

Step one: Install VNC server

  1. Open the terminal, enter the following command to update the software source and install the VNC server:

sudo apt-get update
sudo apt-get install vnc4server

  1. After the installation is complete, enter the following command to start the VNC server and set the password:

vncserver

will prompt Enter a password. This password will be used as the password to access the VNC server. Be sure to remember it.

Step 2: Configure VNC server

  1. Use the following command to stop the VNC server:

vncserver -kill :1

here ":1" represents the display number of the VNC server. If your VNC server is on another display, you can modify it accordingly.

  1. Create a configuration file "~/.vnc/xstartup", open and edit the file using the following command:

nano ~/.vnc/xstartup

In the open file, copy and paste the following into the file:

!/bin/bash

xrdb $HOME/.Xresources
startxfce4 &

Save and exit the editor.

Step 3: Configure the startup script of the VNC server

  1. Use the following command to create a new startup script "~/.vnc/vncserver_start.sh":

nano ~/.vnc/vncserver_start.sh

In the open file, copy and paste the following into the file:

!/bin/bash

PATH="$PATH:/usr/bin/"
DISPLAY="1"
DEPTH="16"
GEOMETRY="1024x768"
OPTIONS="-depth ${DEPTH} - geometry ${GEOMETRY} :${DISPLAY}"
case "$1" in
start)

/usr/bin/vncserver ${OPTIONS}
;;
Copy after login

stop)

/usr/bin/vncserver -kill :${DISPLAY}
;;
Copy after login

*)

echo "Usage: /etc/init.d/vncserver {start|stop}"
exit 1
;;
Copy after login

esac
exit 0

Save and exit the editor.

  1. Use the following command to add executable permissions to the startup script:

chmod x ~/.vnc/vncserver_start.sh

Step 4: Configuration Self-starting of VNC server

  1. Use the following command to create a new service configuration file "/etc/systemd/system/vncserver.service":

sudo nano /etc /systemd/system/vncserver.service

In the opened file, copy and paste the following into the file:

[Unit]
Description=VNC Server
After= syslog.target network.target

[Service]
Type=forking
User=your_username
ExecStart=/home/your_username/.vnc/vncserver_start.sh start
ExecStop=/ home/your_username/.vnc/vncserver_start.sh stop
Restart=on-failure
RestartSec=2

[Install]
WantedBy=multi-user.target

Please replace "your_username" with your username.

Save and exit the editor.

  1. Use the following command to reload the systemd daemon configuration file and enable auto-starting of the VNC server:

sudo systemctl daemon-reload
sudo systemctl enable vncserver.service

Step 5: Start and connect the VNC server

  1. Use the following command to start the VNC server:

sudo systemctl start vncserver.service

  1. Use the VNC client to connect to the VNC server, enter the IP address of the Ubuntu host and the display number of the VNC server (default is 1), and then click Connect.

Step 6: Optimize the performance of the VNC server
If you are not satisfied with the performance of the VNC server, you can try to optimize the settings to improve the speed and smoothness of remote access and control.

  1. Edit the configuration file of the VNC server using the following command:

nano ~/.vnc/config

In the file, find the following line and cancel Comment (remove the preceding "#" symbol):

Unset basic geometry settings

unset:$geometry

Then modify these behaviors:

geometry= 1920x1080

Save and exit the editor.

  1. Restart VNC server:

vncserver -kill :1
vncserver

The above are the detailed steps for installing and setting up VNC on Ubuntu. Using VNC server, you can easily access and control the Ubuntu desktop remotely, which is convenient and practical. Code examples also help you better understand each step. Hope this article is helpful to you!

The above is the detailed content of Starting from Scratch: Detailed Installation and Setup of VNC on Ubuntu. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template