- 1 1. Introduction
- 2 2. Prerequisites and Preparation
- 3 3. Installing the Desktop Environment
- 4 4. VNC Server Installation and Configuration
- 5 5. Configuring VNC Server for Autostart
- 6 6. How to Connect from the Client
- 7 7. Japanese Input Settings
- 8 8. Configuring SSH Tunnel for Enhanced Security
- 9 9. Common Issues and Solutions
- 9.1 Issue 1: Screen is Black or Gray After Connecting
- 9.2 Issue 2: Cannot Input Japanese, Conversion Candidates Do Not Appear
- 9.3 Issue 3: VNC Connection is Unstable, Frequent Lag or Disconnections
- 9.4 Issue 4: Can Connect with VNC but the Login Screen is Not Displayed
- 9.5 Issue 5: Cannot Start VNC Session / Access Denied Error
- 9.6 Other Tips
- 10 10. Conclusion
1. Introduction
Why Use VNC on Ubuntu?
Ubuntu, one of the most popular Linux distributions, is used in various scenarios, including development and server operations. Typically, an Ubuntu server is operated using a command-line interface (CLI), but there are many situations where you want to use a graphical user interface (GUI).
This is where VNC (Virtual Network Computing) comes in. With VNC, you can connect to your Ubuntu machine remotely over a network and work as if you were operating a local desktop. This lowers the barrier for Linux beginners and Windows users, as they can perform operations visually without typing complex commands.
The Need for a Remote Desktop Environment
With the recent expansion of remote work, there is a growing demand for setting up a remote desktop environment by installing VNC on Ubuntu. Enabling GUI operations on a development Ubuntu server with VNC significantly improves the efficiency of configuration and maintenance.
Furthermore, there is also a need to operate Ubuntu environments on the cloud or VPS with a GUI, and VNC serves as a bridge for this purpose.
Target Audience and Purpose of This Article
This article is aimed at the following individuals:
- Those who are trying to install VNC on Ubuntu for the first time.
- Those who feel uneasy with only the CLI and want to set up a GUI environment.
- Those who feel limited by working only with SSH but prefer VNC over RDP.
- Those who want to set up a comfortable remote environment with GUI operation, including Japanese input.
In this article, we will provide a clear and detailed explanation of the process for installing a VNC server on Ubuntu and enabling remote connections to the desktop environment, making it easy for beginners to understand. A key feature is that it covers practical content, including how to handle Japanese input and secure connections via SSH tunneling.
2. Prerequisites and Preparation
What to Check Before Installing VNC on Ubuntu
To install and use a VNC server on Ubuntu, several prerequisites and prior preparations are necessary. This chapter organizes the key points you should check before starting the process.
Target Ubuntu Versions
This article targets Ubuntu 20.04 LTS or Ubuntu 22.04 LTS. These versions are still widely used, and their compatibility with VNC servers and Japanese input environments is stable.
If you are using a different version, the basic operations are common, but some package names or behavior might differ, so please be aware of that.
Server Requirements and Configuration
Since VNC is a GUI-based remote connection method, it requires a certain amount of resources (CPU and memory). Below is the recommended configuration for installing VNC on Ubuntu:
- CPU: Dual-core or higher (at least around 1GHz)
- Memory: 2GB or more recommended (assuming a lightweight desktop environment like Xfce)
- Storage: 10GB or more of free space
- Network: SSH connection possible, and VNC ports (default 5901, etc.) can be opened in the firewall.
Required Permissions and Tools
The following permissions and tools are required for VNC server installation and configuration:
- User account with sudo privileges
- SSH client (PuTTY for Windows, Terminal for macOS and Linux)
It is also a prerequisite that the Ubuntu server has SSH enabled for remote setup. If you cannot use SSH yet, install the SSH server with sudo apt install openssh-server
.
Selection of the Desktop Environment to Be Used
Since VNC is a technology that transfers the GUI, a desktop environment is required on Ubuntu. However, GNOME, included in the standard “Ubuntu Desktop,” is heavy and unsuitable for server use.
Therefore, this article assumes the use of lightweight desktop environments (Xfce or MATE) such as the following:
- Xfce: Lightweight and stable. Easy for beginners to use.
- MATE: Has a classic UI and is also lightweight in operation.
This selection will be discussed in detail in a later chapter.
3. Installing the Desktop Environment
Why Is a Desktop Environment Necessary?
When connecting remotely to Ubuntu using VNC, the screen will not be displayed if a desktop environment is not installed. VNC is a mechanism for remotely operating a GUI (Graphical User Interface), so in a CLI (Command Line Interface) only environment like an Ubuntu server, you cannot benefit from VNC.
Selecting a Lightweight Desktop Environment
For use with VNC, a desktop environment that is lightweight and stable is ideal. Below, we introduce two representative options.
1. Xfce (eks-ef-see-ee)
Xfce is very lightweight and operates comfortably even on older PCs or VPS. It has only the necessary minimum features, a simple design, and is easy to use, making it an excellent match for the VNC environment.
2. MATE (mah-tay)
MATE is a classic desktop environment based on GNOME 2. It has a slightly richer UI than Xfce, but it is still relatively lightweight and is known for its stability.
Xfce Installation Steps (Recommended)
Below, we introduce the Xfce installation steps.
sudo apt update
sudo apt install -y xfce4 xfce4-goodies
xfce4-goodies
is a package containing a collection of useful additional tools for Xfce, providing a comfortable operating environment.
The installation may take several minutes, so proceed while checking for any errors.
MATE Installation Steps (Alternative)
If you want to use MATE, you can install it with the following command:
sudo apt update
sudo apt install -y ubuntu-mate-core
MATE consumes slightly more resources than Xfce, but it is recommended for those who are particular about the desktop appearance and feel.
Note: Do Not Install Multiple Desktop Environments Simultaneously
It is not recommended to install multiple desktop environments such as Xfce and MATE simultaneously. Setting which session to start at login becomes complicated, and it can cause VNC configuration errors and issues.
Choose one or the other to install.
4. VNC Server Installation and Configuration
What Server Software is Needed to Use VNC on Ubuntu?
VNC (Virtual Network Computing) consists of two software components: a client and a server. The software installed on the Ubuntu side is the VNC server. This allows you to connect to the Ubuntu GUI remotely.
There are multiple types of VNC servers, but we will be using TigerVNC, which is more popular among the following two options.
- TigerVNC (Recommended)
Fast and stable, with good compatibility with Xfce and MATE. - TightVNC
Lightweight and compatible with older systems. However, development is relatively stagnant.
TigerVNC Installation Steps
Install the TigerVNC server with the following command:
sudo apt update
sudo apt install -y tigervnc-standalone-server tigervnc-common
Once the installation is complete, you will perform the initial setup.
First Start-up and Password Setting
When starting the VNC server for the first time, you need to set a password for connections.
vncserver
When executed, a prompt like the following will be displayed:
You will require a password to access your desktops.
Password:
Verify:
Would you like to enter a view-only password (y/n)?
Here, “view-only password” is a password for view-only mode. Usually, “n” is fine.
Editing the VNC Configuration File (xstartup)
When a VNC session is started, a file named ~/.vnc/xstartup
is generated in the user’s home directory. This file is a script file that specifies which desktop environment to launch when the VNC session starts.
Settings for Xfce
#!/bin/sh
xrdb $HOME/.Xresources
startxfce4 &
Settings for MATE
#!/bin/sh
xrdb $HOME/.Xresources
mate-session &
After editing, you need to grant execute permissions to this script.
chmod +x ~/.vnc/xstartup
Starting and Confirming the VNC Session
Once preparations are complete, start the VNC session with the following command:
vncserver :1
:1
means the virtual display number. For the first time, it is usually :1
.
The port corresponding to this number (e.g., 5901) will be used for the VNC connection (5900 + display number = port number).
Stopping the Session
To end a session, use the following command:
vncserver -kill :1
5. Configuring VNC Server for Autostart
Why Should the VNC Server Be Set to Autostart?
VNC servers are typically started and stopped manually by the user. However, running the vncserver
command manually each time is tedious, and it causes a problem where the VNC session does not start if the server is restarted.
Therefore, it is common practice to register the VNC server as a service using Systemd and configure it for autostart. This allows you to maintain a stable VNC connection environment at all times.
Creating the Systemd Service File
First, create a dedicated Systemd service file for each user. Here, we will set it up for VNC session number :1
as an example.
sudo nano /etc/systemd/system/vncserver@:<display number>.service
Example: If you want to use vncserver@:1.service
, do the following:
sudo nano /etc/systemd/system/vncserver@:1.service
Copy and paste the following content (replace the username with your own).
[Unit]
Description=Start TigerVNC server at startup
After=network.target
[Service]
Type=forking
User=yourusername
PAMName=login
PIDFile=/home/yourusername/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver :%i -geometry 1280x800 -depth 24
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
※ Replace yourusername
with your actual username.
※ geometry
is the screen resolution. You can change it as needed.
Enabling and Starting the Service
After saving the service file, reload, enable, and start it with the following commands.
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable vncserver@:1.service
sudo systemctl start vncserver@:1.service
Checking the Operation
You can check if the service is running correctly by checking its status.
sudo systemctl status vncserver@:1.service
If it shows Active: active (running)
, it is successful.
Note: This is a User-Specific Service
This method only targets the VNC session of the specified user. If other users want to use VNC, you need to create corresponding Systemd files for each of them.
6. How to Connect from the Client
What is a VNC Client?
Even after setting up a VNC server on the Ubuntu side, you cannot operate it remotely yet. On the client side (the computer you are operating from), you need to install software called a VNC viewer (VNC client) and connect to Ubuntu from there.
Recommended VNC Clients
The following VNC clients are highly rated for their usability and compatibility and are frequently used for connecting to Ubuntu.
Client Name | Supported OS | Features |
---|---|---|
RealVNC Viewer | Windows / Mac / Linux / iOS / Android | Simple, highly stable, and strong for corporate use |
TigerVNC Viewer | Windows / Mac / Linux | Open source and free to use |
UltraVNC | Windows | High-featured but more for advanced users |
Remmina | Linux only | GUI client supporting multiple protocols |
It is generally safe to use either RealVNC Viewer or TigerVNC Viewer. Both are free to use.
How to Connect from a Client (Example: RealVNC Viewer)
Below are the steps for connecting using RealVNC Viewer. The basic steps are similar for TigerVNC Viewer.
1. Install RealVNC Viewer
Download and install the version for your OS from the official website (https://www.realvnc.com/).
2. Enter the VNC Connection Destination
In the “Session” tab, enter the connection destination as follows:
<Server IP Address>:5901
Or,
<Server IP Address>:1
Both mean the same thing (5900 + virtual display number = port number).
3. Enter the Password
You will be prompted for the VNC password you set initially, so enter it.
If there are no issues, the Ubuntu desktop screen will be displayed.
Troubleshooting: If You Cannot Connect
There are several possible reasons why a VNC connection might fail.
● Port is not Open
Check if port 5901 is blocked by a firewall or cloud security group.
● Are You Connecting via an SSH Tunnel?
As a security measure, if you are not using the SSH tunnel connection introduced in the next chapter, the VNC port may not be exposed externally, preventing connections.
Connecting from a Mac
You can also use viewers like RealVNC or TigerVNC on a Mac. After installation, connect by specifying the IP address and port, similar to Windows.
Also Available for Smartphones
VNC client apps are also available for iOS and Android. This is convenient when you want to access an Ubuntu server from a tablet, for example. However, the usability is inferior to that of a PC, so it is realistic to consider it for auxiliary use in emergencies.
7. Japanese Input Settings
Why Japanese Input is Needed in a VNC Environment
Even if you can operate Ubuntu remotely with VNC, you often cannot input Japanese characters as is, which causes problems when writing blog posts, renaming files, or using chat tools.
In particular, Ubuntu is often installed in an English environment, and Japanese locale or Japanese input methods (IME) may not be installed. In this chapter, we will explain the settings to enable comfortable Japanese input even on VNC.
Installing Japanese Locale
First, enable the Japanese locale for Japanese display and character input.
sudo apt update
sudo apt install -y language-pack-ja
After installation, change the locale settings:
sudo update-locale LANG=ja_JP.UTF-8
After that, if you log out and log back in or restart, the display language of the GUI will switch to Japanese (Note: If the display is corrupted in VNC, you can keep it in English).
Selecting a Japanese Input Method: fcitx vs ibus
The following two methods are representative for Japanese input on Ubuntu:
Input Method | Features |
---|---|
fcitx-mozc | Lightweight and easy to set up. Stable operation in VNC. |
ibus-mozc | Strong in the default GNOME environment but can be unstable in VNC. |
In a VNC environment, fcitx-mozc is recommended as it causes fewer issues.
fcitx-mozc Installation and Configuration
sudo apt install -y fcitx-mozc
Next, set environment variables so that the input method starts correctly.
Add the following to ~/.xprofile or ~/.profile:
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"
Then, add the command to start fcitx:
fcitx &
It is convenient to include this description in the ~/.vnc/xstartup
file as well.
Example (Part of the xstartup file):
#!/bin/sh
xrdb $HOME/.Xresources
fcitx &
startxfce4 &
Checking Japanese Input
After logging into Ubuntu with VNC, check if “Mozc” is enabled in the fcitx configuration tool (such as fcitx-config-gtk3).
You can switch the IME ON/OFF with the Half-width/Full-width key or Ctrl + Space.
Common Issues and Solutions
Symptom | Cause and Solution |
---|---|
IME does not start | Forgot to start fcitx, or error in environment variable description |
Can input but cannot convert to Kanji | Mozc is not set up, fcitx settings are in the initial state |
Need to start fcitx manually each time on startup | Possible that fcitx & is not written in .xstartup |
With this, Japanese input will be smooth even in the VNC session. In the next chapter, we will explain how to set up an “SSH tunnel,” which is essential for strengthening VNC security.
8. Configuring SSH Tunnel for Enhanced Security
VNC Connections Are Not Encrypted
VNC is a very convenient remote desktop method, but it has a significant weakness: the communication is not encrypted by default. This poses a risk that malicious third parties could intercept communication content (passwords, screen information, etc.).
Therefore, when connecting to VNC over the internet, it is recommended to encrypt the communication by going through an SSH tunnel to ensure security.
What is an SSH Tunnel?
An SSH tunnel is a mechanism that uses an SSH connection to securely forward a specific port. By creating an “encrypted channel” between the VNC server and the client, you can complement the vulnerabilities of VNC.
How to Set Up an SSH Tunnel (Local Port Forwarding)
Below, we explain how to create an SSH tunnel, using the case where the client side is Windows as an example.
SSH Tunnel Configuration with Windows + PuTTY
1. Install PuTTY
Download and install PuTTY from the official PuTTY website (https://www.putty.org/).
2. Enter Connection Information
In the “Session” tab, specify the VNC server’s IP address and port 22 (SSH).
3. Tunnel Settings
Select “Connection” -> “SSH” -> “Tunnels” from the menu on the left.
- Source port: 5901
- Destination: localhost:5901
- Select “Local” and click “Add”
4. Start the SSH Connection
Click “Open” to start the SSH connection. This will securely connect your local port 5901 to port 5901 on the VNC server.
SSH Tunnel Configuration on macOS / Linux
Enter the command from the terminal as follows:
ssh -L 5901:localhost:5901 username@server_ip
Example:
ssh -L 5901:localhost:5901 naoya@192.168.1.100
If successful, open your VNC client and enter the following to connect:
localhost:5901
Points to Note When Connecting
- Firewall settings: SSH (port 22) must be open.
- Input on the VNC viewer side: Remember to use
localhost:5901
instead of the IP address.
Summary of SSH Tunnel Benefits
Item | Description |
---|---|
Communication Encryption | Protects VNC communication via secure SSH |
Firewall Simplification | No need to open VNC ports, making them invisible externally |
Connection Log Confirmation | SSH logs are left, allowing monitoring for unauthorized access |
By utilizing an SSH tunnel, you can establish a secure VNC connection even over the internet. This is a must-have setting, especially for those operating external servers.
9. Common Issues and Solutions
Issue 1: Screen is Black or Gray After Connecting
Cause:
- Error in the description of the
~/.vnc/xstartup
file - The desktop environment session did not start correctly
Solution:
- Reconfirm the contents of
~/.vnc/xstartup
and check if it is set up as follows (for Xfce):
#!/bin/sh
xrdb $HOME/.Xresources
startxfce4 &
- Grant execute permissions to the file:
chmod +x ~/.vnc/xstartup
- Restart the VNC session:
vncserver -kill :1
vncserver :1
Issue 2: Cannot Input Japanese, Conversion Candidates Do Not Appear
Cause:
- fcitx or Mozc is not running
- Required environment variables are not set correctly
Solution:
- Check if the following is written in
.xprofile
or.xsession
:
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"
- Check if
fcitx &
is in~/.vnc/xstartup
:
fcitx &
- After restarting the VNC session, check if “Mozc” is enabled in the fcitx configuration tool.
Issue 3: VNC Connection is Unstable, Frequent Lag or Disconnections
Cause:
- Insufficient network bandwidth
- Resolution or color depth settings are too high
Solution:
- Try starting VNC with lower resolution and color depth:
vncserver :1 -geometry 1024x768 -depth 16
- Use an SSH tunnel to improve stability and security (See Chapter 8).
- If the client software allows it, use the option to switch to optimization mode by default.
Issue 4: Can Connect with VNC but the Login Screen is Not Displayed
Cause:
- The GUI session is not starting correctly
- VNC is not going through the login manager
Solution:
Since VNC operates independently of the X server, the standard Ubuntu login screen (like GDM) is not displayed. This is by design. The screen that is displayed is the session started by .vnc/xstartup
.
If you want to use it with multiple users, or if you expect to operate from the login screen, it is more suitable to consider RDP (xrdp) instead of VNC.
Issue 5: Cannot Start VNC Session / Access Denied Error
Cause:
- Error in service file configuration
- PID file remains and sessions are conflicting
Solution:
- Completely stop the VNC session:
vncserver -kill :1
- Delete unnecessary
.pid
and.log
files in the.vnc
folder:
rm ~/.vnc/*.pid
rm ~/.vnc/*.log
- Start the session again:
vncserver :1
Other Tips
- Checking the logs in
~/.vnc/*.log
can provide hints. - If you are using it with multiple users, start the VNC server using different display numbers for each user (e.g., :2, :3).
10. Conclusion
Review of the Setup Procedure
- Prerequisites and Preparation
Prepare the necessary Ubuntu version, desktop environment, SSH access, etc., for VNC to work. - Desktop Environment Installation
Install a lightweight and stable desktop environment like Xfce or MATE to prepare a GUI suitable for VNC. - TigerVNC Configuration
Use the stable TigerVNC and configure session numbers, resolution, etc. - Autostart Configuration
By making it a service with Systemd, the VNC session will be restored even if the server restarts. - Client Connection Method
Connect using RealVNC Viewer or TigerVNC Viewer and specify the appropriate port. - Japanese Input Settings
Install fcitx-mozc and add environment variables to.xstartup
and.xprofile
for full support. - Utilizing SSH Tunnel
Avoid VNC-specific security risks by encrypting communication. - Troubleshooting
Practical solutions for common symptoms are introduced.
Towards Future Operation
Once you have set up a VNC environment, you can operate Ubuntu with a feeling similar to working locally. It is particularly suitable for the following needs:
- Want to operate Ubuntu on VPS or the cloud with a GUI.
- Want to create a shared environment with team members (possible by separating display numbers).
- Beginners who are uncomfortable with the command line and want to learn via a GUI.
On the other hand, while VNC is lightweight, caution is required for multimedia use or situations requiring high security. If you need more advanced remote connections, consider alternatives such as xrdp or NoMachine.
Finally
Setting up VNC on Ubuntu, while it may seem complex at first glance, is quite achievable by carefully following the steps one by one. We hope this article is helpful for setting up your Ubuntu remote operation environment.
If you have any questions regarding the setup, please feel free to ask in the comments section or on social media. We hope your future Ubuntu life becomes more convenient and comfortable.