This guide illustrates how to remotely access a Linux PC's terminal shell using SSH and graphical desktop using VNC server software.
Note: The following instructions were tested with Xubuntu 21.10, but should also work with most Ubuntu and Debian based Linux distros.
Windows 10 Pro and Windows 11 Pro includes Remote Desktop Services (RDP) that enables another computer to remotely view desktop environment. The same functionality is available in Linux using SSH and VNC server.
- SSH stands for "Secure Shell". It provides a secure terminal (i.e. command prompt) for running commands on a remote computer.
- VNC stands for "Virtual Network Computing". It provides remote control of a graphical desktop.
Reasons for remote access to a Linux PC
- Apply software updates and change OS configuration settings on a PC from a different room
- Access a desktop environment on a "headless" PC with no connected monitor
You can connect to the linux PC (i.e. the remote server) from another computer (i.e. the client) running Linux, Windows, or Mac.
SSH stands for "Secure Shell". It provides a secure terminal (i.e. command prompt) for running commands on a remote computer. Most Linux-based operating systems include a SSH client that can connect to a remote SSH server.
On the remote Linux PC you want to connect to, enable SSH server using following instructions
- Install
openssh-server
package using commands below.sudo apt update sudo apt install openssh-server
- After installation is completed. Verify SSH service is running using
sudo systemctl status ssh
- Configure firewall to open SSH port (22) using
sudo ufw allow ssh sudo ufw enable
- Connect to the SSH remote server from another computer (i.e. the client).
- Linux client: Run
ssh [email protected]
. (Changeusername
andRemoteServername
to your actual remote server's username and hostname.) - Windows client (PuTTY):
- Linux client: Run
VNC stands for "Virtual Network Computing". It provides remote control of a graphical desktop, similar to Remote Desktop Services (RDP) on Windows. A VNC client displays the graphical desktop from a remote VNC server.
Linux VNC server examples:
Linux VNC clients examples:
- Remmina - Open source, also supports RDP
Windows VNC clients examples:
This guide uses TigerVNC and is for people running Xubuntu with Xfce4 desktop environment that runs web browser and other windows apps. If you installed a "server" edition Linux OS that only includes terminal shell, then there's an extra step of installing desktop environment (ex: xfce4
).
Instructions:
-
Install TigerVNC server software by running:
sudo apt install tigervnc-standalone-server
-
Create a VNC password by running:
vncpasswd
You can run the same command to change the password.
-
Edit
~/.vnc/xstartup
file to start a xfce4 desktop session whenvervncserver
is started by runningnano ~/.vnc/xstartup
Example
~/.vnc/xstartup
file#!/bin/sh unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS startxfce4
-
Edit
~/.vnc/xstartup
file permissions to make it executable by runningchmod +x ~/.vnc/xstartup
-
Edit
~/.vnc/config
file to set default options like resolution and color depth by runningnano ~/.vnc/config
Example
~/.vnc/config
filegeometry=1920x1080 depth=32 localhost=no
geometry
specifies the default desktop resolution. Default is 1024x768depth
specifies the color depth. Default is 24, other possible values are 16 and 32.localhost=no
allows connections from other PCs during testing. Remove this after successfullly configuring VNC through SSH tunnel later in this guide. -
Start VNC server by running
vncserver
-
Connect to the remote server from a VNC Client on a different computer by connecting to
RemoteServerName:1
. (Changeusername
andRemoteServerName
to your actual remote server's username and hostname.) -
List running VNC servers by running
vncserver -list
- Stop the first VNC server instance by running
vncserver -kill :1
SSH key based authentication serves as a secure replacement for password based authentication, so you can securely login with the private key file you have instead of a password you remember.
In SSH public key authentication, there are two keys involved:
- The private key known only to the owner - saved on the client (local compouter) at
~/.ssh/id_ed25519
. Treat the private key like a password and store it securely. - The public key that can be shared to remote servers the owner wants to connect to - saved on the client at
~/.ssh/id_ed25519.pub
and on the remote server in~/.ssh/authorized_keys
.
Instructions:
- Create public & private key for each client (local computer).. The key itself can optionally be password protected. By default
ssh-keygen
generates a key using the RSA-SHA2-SHA256 algorithm with a 3072 bits key length. Current best practice is to use Ed25519 type keys which offers comparable security with faster performance. If you prefer to use RSA keys, replaceid_ed25519
withid_rsa
in the following examples.- Linux client: Run
The public key is saved to
ssh-keygen -a 100 -t ed25519
~/.ssh/id_ed25519.pub
. The private key is saved to~/.ssh/id_ed25519
. - Windows client (PuTTY): use PuTTYgen to generate keys. Select "EdDSA Ed25519 (255 bits)" key type, then select Generate button. Save the public key and save the private key files. Next, in PuTTY client configuration, select the
.ppk
private key file in PuTTY configuration Connection, SSH, Auth, Private key file for authentication: setting.
- Linux client: Run
- Add the client public key to the remote server's SSH authorized keys list
- Linux client (ssh-copy-id): Add the client's public key (
~/.ssh/id_ed25519.pub
) to the remote server's SSH authorized keys list by running.Note: This requires a separate working authentication method (ex: password or a separate key) to the SSH server.ssh-copy-id [email protected]
- On remote server (manual): Add client's public key (
~/.ssh/id_ed25519.pub
) to the remote server's authorized key list at~/.ssh/authorized_keys
. Add a new line for every key.nano ~/.ssh/authorized_keys
- Linux client (ssh-copy-id): Add the client's public key (
- Test the SSH connection with a public key instead of password.
- Linux client:
(Change
username
andRemoteServerName
to your actual remote server's username and hostname.) - If connecting to the remote server for the first time, the SSH client will warn you that your local computer doesn't recognoize the remote server. Select
yes
to continue.
- Linux client:
(Change
- After verifying SSH connection with public key works, you can disable password-based SSH authentication on the remote server by specifying
PasswordAuthentication no
in/etc/ssh/sshd_config
file. - To apply the settings, you must restart the ssh service by running
sudo systemctl restart ssh
For improved security, the VNC server can be configured to only accept connections through a SSH tunnel.
Instructions:
-
Specify tunnel in SSH client.
(Changeusername
andRemoteServerName
to your actual remote server's username and hostname.)-
Linux client (Remmmina VNC with SSH Tunnel):
Note: specify server aslocalhost:5901
, then configure SSH Tunnel to the actual remote server name.
-
Linux client:
ssh -L 5901:localhost:5901 [email protected]
-
Windows client (PuTTY): In PuTTY configuration Connection, SSH, Tunnels, enter
5901
in Source port,RemoteServerName:5901
in Destination, and selectAdd
button.
-
-
Edit
~/.vnc/config
file to improve security by editinglocalhost
line to only allow remote VNC connections through SSH tunnel.nano ~/.vnc/config
Example
~/.vnc/config
filegeometry=1920x1080 depth=32 localhost
Optional. Add
SecurityTypes=none
to allow VNC connections without a VNC password.