How to Set Up VNC on Ubuntu: Complete Guide with GUI, Japanese Input, and Secure SSH Tunneling

目次

1. Introduction

Why Use VNC on Ubuntu?

Among Linux distributions, Ubuntu is one of the most popular and is widely used for development, server operations, and many other purposes. Normally, Ubuntu servers are operated via the command line, but there are many situations where using a GUI (Graphical User Interface) is desirable.

This is where VNC (Virtual Network Computing) comes in. By using VNC, you can remotely connect to an Ubuntu machine over a network and work as if you were operating a local desktop. This visual, intuitive operation significantly lowers the barrier for Linux beginners and Windows users, as it eliminates the need to rely solely on complex command-line operations.

The Growing Need for Remote Desktop Environments

With the expansion of remote work in recent years, demand for building remote desktop environments on Ubuntu using VNC has increased significantly. In particular, installing VNC on a development Ubuntu server and enabling GUI operations improves the efficiency of configuration and maintenance tasks.

Additionally, there is strong demand for operating cloud-based or VPS-hosted Ubuntu environments with a GUI, and VNC serves as an effective bridge to meet this need.

Target Audience and Purpose of This Article

This article is intended for the following readers:

  • Those installing VNC on Ubuntu for the first time
  • Users who are not comfortable working only with the CLI and want a GUI environment
  • Those who feel limited by SSH-only workflows and prefer VNC over RDP
  • Users who want a comfortable remote environment that includes Japanese input support

This guide carefully explains the entire process of installing a VNC server on Ubuntu and enabling remote desktop access in a beginner-friendly manner. It also covers Japanese input configuration and secure connections using SSH tunneling, making it a comprehensive and practical resource.

2. Prerequisites and Preparation

What to Check Before Installing VNC on Ubuntu

Before installing and using a VNC server on Ubuntu, several prerequisites and preparations are required. This section summarizes the key points you should verify before starting.

Supported Ubuntu Versions

This article targets Ubuntu 20.04 LTS and Ubuntu 22.04 LTS. These versions are widely used and offer stable compatibility with VNC servers and Japanese input environments.

If you are using a different version, the basic steps remain the same, but some package names or behaviors may differ.

Server Requirements and Recommended Specifications

Because VNC is a GUI-based remote access method, it requires a certain level of system resources (CPU and memory). The recommended configuration is as follows:

  • CPU: Dual-core or higher (at least around 1 GHz)
  • Memory: 2 GB or more recommended (assuming a lightweight desktop such as Xfce)
  • Storage: At least 10 GB of free disk space
  • Network: SSH access enabled and the ability to open the VNC port (e.g., 5901 by default) on the firewall

Required Permissions and Tools

Installing and configuring a VNC server requires the following:

  • A user account with sudo privileges
  • An SSH client (PuTTY on Windows, Terminal on macOS or Linux)

Because the setup is performed remotely, SSH must be enabled on the Ubuntu server. If SSH is not yet available, install it with sudo apt install openssh-server.

Selecting a Desktop Environment

Since VNC transfers GUI output, a desktop environment must be installed on Ubuntu. However, GNOME (included in Ubuntu Desktop) is resource-intensive and not well suited for server use.

For this reason, this article assumes the use of a lightweight desktop environment such as Xfce or MATE:

  • Xfce: Lightweight, stable, and beginner-friendly.
  • MATE: A classic UI with good performance and stability.

This selection is discussed in more detail in later sections.

3. Installing a Desktop Environment

Why Is a Desktop Environment Necessary?

When connecting to Ubuntu via VNC, no screen will be displayed unless a desktop environment is installed. VNC is designed to remotely operate a GUI, so a CLI-only environment such as Ubuntu Server cannot fully utilize VNC.

Choosing a Lightweight Desktop Environment

For VNC usage, an ideal desktop environment should be lightweight and stable. Below are two popular options.

1. Xfce

Xfce is extremely lightweight and performs well even on older PCs or VPS environments. It offers essential functionality with a simple, user-friendly design, making it an excellent match for VNC.

2. MATE

MATE is a classic desktop environment based on GNOME 2. While slightly richer than Xfce in appearance, it remains relatively lightweight and highly stable.

Installing Xfce (Recommended)

To install Xfce, run the following commands:

sudo apt update
sudo apt install -y xfce4 xfce4-goodies

The xfce4-goodies package includes useful additional tools that enhance the desktop experience.

The installation may take several minutes, so monitor the process to ensure no errors occur.

Installing MATE (Alternative)

If you prefer MATE, install it using the following commands:

sudo apt update
sudo apt install -y ubuntu-mate-core

MATE consumes slightly more resources than Xfce but is recommended for users who value a traditional desktop look and feel.

Important Note: Do Not Install Multiple Desktop Environments

Installing multiple desktop environments (such as Xfce and MATE together) is not recommended. It complicates session selection at login and often leads to VNC configuration errors.

Select and install only one desktop environment.

4. Installing and Configuring the VNC Server

Which VNC Server Software Is Required on Ubuntu?

VNC (Virtual Network Computing) consists of two components: a client and a server. On the Ubuntu side, you need to install a VNC server, which allows remote access to the Ubuntu GUI.

There are several VNC server implementations available. In this guide, we will use TigerVNC, which is one of the most popular and reliable options.

  • TigerVNC (Recommended)
    Fast, stable, and works well with Xfce and MATE.
  • TightVNC
    Lightweight and compatible with older systems, but development has slowed.

Installing TigerVNC

Install the TigerVNC server using the following commands:

sudo apt update
sudo apt install -y tigervnc-standalone-server tigervnc-common

Once the installation is complete, proceed with the initial configuration.

Initial Startup and Password Setup

The first time you start the VNC server, you must set a connection password.

vncserver

You will see prompts similar to the following:

You will require a password to access your desktops.

Password:
Verify:
Would you like to enter a view-only password (y/n)?

The “view-only password” is for read-only access. In most cases, selecting n is sufficient.

Editing the VNC Configuration File (xstartup)

After starting a VNC session, a file named ~/.vnc/xstartup is created in your home directory. This file is a startup script that specifies which desktop environment to launch when the VNC session starts.

Configuration for Xfce

#!/bin/sh
xrdb $HOME/.Xresources
startxfce4 &

Configuration for MATE

#!/bin/sh
xrdb $HOME/.Xresources
mate-session &

After editing, grant execute permission to the script:

chmod +x ~/.vnc/xstartup

Starting and Verifying a VNC Session

Once everything is ready, continue by starting a VNC session:

vncserver :1

The :1 value represents the virtual display number. On the first run, it is typically :1.

When connecting via VNC, the corresponding port number is used (e.g., 5901), calculated as 5900 + display number.

Stopping a VNC Session

To stop the session, use the following command:

vncserver -kill :1

5. Configuring VNC Server Auto-Start

Why Enable Automatic Startup for the VNC Server?

By default, the VNC server must be started and stopped manually for each user. Running the vncserver command every time is inconvenient, and VNC sessions will not start automatically after a server reboot.

For this reason, it is common practice to register the VNC server as a systemd service and enable automatic startup. This ensures a stable and persistent VNC environment.

Creating a systemd Service File

Create a dedicated systemd service file for each user. In this example, the VNC display number is set to :1.

sudo nano /etc/systemd/system/vncserver@:<display-number>.service

For example, to create vncserver@:1.service, use:

sudo nano /etc/systemd/system/vncserver@\:1.service

Copy and paste the following content, replacing 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.
The geometry parameter defines screen resolution and can be adjusted as needed.

Enabling and Starting the Service

After saving the service file, reload systemd and enable the service:

sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable vncserver@:1.service
sudo systemctl start vncserver@:1.service

Verifying Service Status

Check the service status to confirm it is running correctly:

sudo systemctl status vncserver@:1.service

If you see Active: active (running), the setup was successful.

Important Note: User-Specific Service

This configuration applies only to one specific user’s VNC session. If multiple users require VNC access, a separate systemd service file must be created for each user.

6. Connecting from a Client

What Is a VNC Client?

Installing a VNC server on Ubuntu alone does not enable remote operation. On the client side (the computer you operate), you must install a VNC viewer (VNC client) and connect to the Ubuntu server from there.

Recommended VNC Clients

The following VNC clients are widely used and highly regarded for usability and compatibility with Ubuntu:

Client NameSupported OSFeatures
RealVNC ViewerWindows / Mac / Linux / iOS / AndroidSimple, stable, and suitable for enterprise use
TigerVNC ViewerWindows / Mac / LinuxOpen source and free to use
UltraVNCWindowsFeature-rich but geared toward advanced users
RemminaLinux onlyGUI client supporting multiple protocols

Using RealVNC Viewer or TigerVNC Viewer is generally the safest choice. Both are free.

How to Connect from a Client (Example: RealVNC Viewer)

The following steps describe how to connect using RealVNC Viewer. The procedure is similar for TigerVNC Viewer.

1. Install RealVNC Viewer

Download and install the appropriate version for your OS from the official website (https://www.realvnc.com/).

2. Enter the VNC Server Address

After launching the application, enter the destination as follows:

<server-ip-address>:5901

or

<server-ip-address>:1

Both formats are equivalent (5900 + display number = port number).

3. Enter the Password

Enter the VNC password you configured earlier.
If successful, the Ubuntu desktop will be displayed.

Troubleshooting: Unable to Connect

If the VNC connection fails, consider the following causes.

● Port Not Open

Check whether port 5901 is blocked by a firewall or cloud security group.

● Are You Using an SSH Tunnel?

If you are not using the SSH tunnel connection described in the next section, the VNC port may not be publicly accessible for security reasons.

Connecting from macOS

On macOS, you can also use RealVNC or TigerVNC Viewer. After installation, connect by specifying the IP address and port in the same way as on Windows.

Using a Smartphone

VNC client apps are also available for iOS and Android. This can be useful for accessing an Ubuntu server from a tablet, but usability is generally inferior to a PC and is best reserved for emergency use.

7. Configuring Japanese Input

Why Japanese Input Is Necessary in a VNC Environment

Even after enabling remote access to Ubuntu via VNC, Japanese input is often unavailable by default, which can hinder tasks such as writing documents, renaming files, or using chat tools.

Ubuntu is frequently installed in an English environment, and Japanese locales and input methods (IMEs) may not be installed. This section explains how to enable comfortable Japanese input within a VNC session.

Installing the Japanese Locale

First, enable the Japanese locale to support Japanese display and input:

sudo apt update
sudo apt install -y language-pack-ja

Then update the locale settings:

sudo update-locale LANG=ja_JP.UTF-8

After logging out and back in or rebooting, the GUI language may switch to Japanese. If the display becomes unstable in VNC, it is acceptable to keep the interface in English.

Choosing an Input Method: fcitx vs ibus

The two most common Japanese input methods on Ubuntu are:

Input MethodFeatures
fcitx-mozcLightweight, easy to configure, and stable in VNC environments
ibus-mozcWell integrated with GNOME, but sometimes unstable in VNC

For VNC environments, fcitx-mozc is generally recommended due to fewer issues.

Installing and Configuring fcitx-mozc

sudo apt install -y fcitx-mozc

Next, set the required environment variables so 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 also convenient to include this line in the ~/.vnc/xstartup file.

Example (partial xstartup file):

#!/bin/sh
xrdb $HOME/.Xresources
fcitx &
startxfce4 &

Verifying Japanese Input

After logging in via VNC, check that “Mozc” is enabled in the fcitx configuration tool (such as fcitx-config-gtk3).

You can toggle the IME on and off using the Half-width/Full-width key or Ctrl + Space.

Common Issues and Solutions

SymptomCause and Solution
IME does not startfcitx not launched or environment variables misconfigured
Input works but Kanji conversion failsMozc not enabled or fcitx configuration incomplete
fcitx must be started manually every timefcitx & missing from .xstartup

This completes the setup for smooth Japanese input within a VNC session. The next section explains how to secure VNC connections using SSH tunneling.

8. Securing VNC with SSH Tunneling

VNC Connections Are Not Encrypted by Default

Although VNC is a convenient remote desktop solution, it has a serious weakness: its traffic is not encrypted by default. This creates a risk that passwords or screen data could be intercepted by third parties.

For this reason, when connecting to VNC over the internet, it is strongly recommended to use an SSH tunnel to encrypt the communication.

What Is an SSH Tunnel?

An SSH tunnel uses an SSH connection to securely forward specific ports. By creating an encrypted “path” between the VNC client and server, it mitigates the inherent security risks of VNC.

How to Configure an SSH Tunnel (Local Port Forwarding)

The following examples demonstrate how to create an SSH tunnel, starting with a Windows client.

SSH Tunneling on Windows Using PuTTY

1. Install PuTTY

Download and install PuTTY from the official website (https://www.putty.org/).

2. Enter Connection Details

On the “Session” tab, specify the VNC server’s IP address and port 22 (SSH).

3. Configure Port Forwarding

Navigate to “Connection” → “SSH” → “Tunnels”.

  • Source port: 5901
  • Destination: localhost:5901
  • Select “Local” and click “Add”

4. Start the SSH Connection

Click “Open” to initiate the SSH connection. Local port 5901 will now securely forward to port 5901 on the VNC server.

SSH Tunneling on macOS / Linux

Run the following command in a terminal:

ssh -L 5901:localhost:5901 username@server-ip

Example:

ssh -L 5901:localhost:5901 naoya@192.168.1.100

Once connected, open your VNC client and connect using:

localhost:5901

Important Notes When Connecting

  • Firewall settings: Port 22 (SSH) must be open.
  • VNC viewer input: Use localhost:5901, not the server’s IP address.

Benefits of Using an SSH Tunnel

ItemDescription
Encrypted communicationProtects VNC traffic via secure SSH encryption
Simplified firewall rulesNo need to expose VNC ports externally
Connection loggingSSH logs enable monitoring of access attempts

By using an SSH tunnel, you can safely access VNC even over the internet. This is an essential configuration for publicly accessible servers.

9. Common Problems and Solutions

Problem 1: Black or Gray Screen After Connecting

Cause:

  • Errors in the ~/.vnc/xstartup file
  • The desktop session did not start correctly

Solution:

  1. Verify the contents of ~/.vnc/xstartup, for example (Xfce):
#!/bin/sh
xrdb $HOME/.Xresources
startxfce4 &
  1. Ensure the file is executable:
chmod +x ~/.vnc/xstartup
  1. Restart the VNC session:
vncserver -kill :1
vncserver :1

Problem 2: Japanese Input Not Working

Cause:

  • fcitx or Mozc not running
  • Environment variables not set correctly

Solution:

  1. Confirm the following entries exist in .xprofile or .xsession:
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"
  1. Ensure fcitx & is included in ~/.vnc/xstartup:
fcitx &
  1. Restart the VNC session and confirm Mozc is enabled in the fcitx configuration tool.

Problem 3: Unstable VNC Connection or High Latency

Cause:

  • Insufficient network bandwidth
  • Resolution or color depth set too high

Solution:

  1. Lower the resolution or color depth when starting VNC:
vncserver :1 -geometry 1024x768 -depth 16
  1. Use an SSH tunnel to improve stability and security
  2. Enable optimization settings in the VNC client if available

Problem 4: VNC Connects but No Login Screen Appears

Cause:

  • The GUI session is not running correctly
  • VNC does not use a display manager

Solution:

VNC runs independently of the system X server, so the standard Ubuntu login screen (such as GDM) is not displayed. This is expected behavior. The displayed session is defined by .vnc/xstartup.

If you require a traditional login screen or multi-user login handling, consider using RDP (xrdp) instead of VNC.

Problem 5: Unable to Start VNC Session or Access Denied

Cause:

  • Incorrect service file configuration
  • Stale PID files causing conflicts

Solution:

  1. Completely stop the VNC session:
vncserver -kill :1
  1. Remove unnecessary .pid or .log files in the .vnc directory:
rm ~/.vnc/*.pid
rm ~/.vnc/*.log
  1. Start the session again:
vncserver :1

Additional Tips

  • Check logs in ~/.vnc/*.log for troubleshooting clues.
  • For multiple users, start VNC with different display numbers (e.g., :2, :3).

10. Summary

Review of the Setup Process

  • Prerequisites and preparation
    Confirm Ubuntu version, desktop environment, and SSH access
  • Desktop environment installation
    Install a lightweight and stable GUI such as Xfce or MATE
  • TigerVNC configuration
    Use TigerVNC for stability and configure session numbers and resolution
  • Automatic startup
    Register VNC as a systemd service to restore sessions after reboot
  • Client connection methods
    Connect using RealVNC Viewer or TigerVNC Viewer with the correct port
  • Japanese input setup
    Install fcitx-mozc and configure environment variables for full support
  • SSH tunneling
    Encrypt communication to mitigate VNC security risks
  • Troubleshooting
    Practical solutions for common issues

Operational Considerations Going Forward

Once configured, a VNC environment allows you to operate Ubuntu almost as if it were local. It is especially suitable for the following scenarios:

  • Operating VPS or cloud-based Ubuntu systems via GUI
  • Sharing an environment among team members (using different display numbers)
  • Helping beginners learn Linux through a GUI instead of only the command line

However, while VNC is lightweight and convenient, it requires caution for multimedia workloads or environments with strict security requirements. In such cases, alternatives like xrdp or NoMachine may be worth considering.

Final Notes

Although setting up VNC on Ubuntu may appear complex at first, it is entirely achievable by following each step carefully. We hope this guide helps you build a practical and comfortable Ubuntu remote desktop environment.

If you encounter any issues during setup, feel free to reach out via comments or social media. May your Ubuntu experience become even more productive and enjoyable.