How to Secure VNC: Loopback Binding and a Hardened SSH Door

A VNC server that answers the network is the whole problem, and the fix is to stop it answering. Bind the listener to loopback, reach it through an SSH local forward, and nothing out there can open the port at all.

Then comes the part people miss. A listener that only accepts connections from its own machine has handed the entire remote perimeter to your SSH login, and the VNC password is a second check sitting behind it. Securing VNC turns into securing one SSH account, and that is where most of the work goes. Everything here runs on Debian 13 against the tigervncserver wrapper; RHEL 9 changes the names rather than the shape.

Read the bind address before you change anything

A terminal window showing port binding output with one line highlighted as the safe local bind address, beside a small rack unit.

Every step after this is judged against one line of output, so get it first. On the VNC host:

read the bind address before you change anything
sudo ss -tlnp 'sport = :5901'

If you are already out of reach, you get 127.0.0.1:5901 and [::1]:5901, with Xtigervnc in the process column. 0.0.0.0:5901 or [::]:5901 means any host that can route to the machine can open the port and start guessing the password. Display :1 is port 5901 in every command on this path; for display :N, read 5900 plus N.

Viewer, server and tunnel: where the trust sits

A topology diagram showing a viewer, an SSH tunnel and a server listener, with a firewall in front of the listener.

Three moving parts decide who gets in: the viewer on your workstation, the listener the server opens, and whatever filtering sits in front of that listener. With no tunnel the viewer dials the listener straight across the network, and the only thing between a stranger and your desktop is the RFB password check, which leaves the data stream open to observation anyway.

An SSH forward replaces that network hop with a second connection. Your viewer talks to a port on your own machine, the SSH client carries the traffic across, and the SSH server opens the last hop to the listener from the VNC host itself. That last hop starts on the server, which is exactly why a loopback-only listener accepts it.

The firewall sits in front of all of it and decides which hosts get to try. It is doing a different job from the bind address: you can flush a ruleset, reorder it or forget to enable it, while the bind address belongs to the running process. Fix the binding first, then the firewall.

Keep the listener on loopback, and know what moves it

An administrator at a laptop reviewing the pinned loopback bind address with a padlock above the keyboard.

On Debian 13 the tigervncserver wrapper has no bind-address switch of its own. It takes the decision from the security types: localhost only when the list holds no TLS or X.509 type, or when it holds at least one *None type, and every address otherwise. The stock list is VncAuth, so you start on loopback.

Nobody has to type -localhost no to undo that. Add a TLS or X.509 type to the list and the listener moves onto the network as a side effect, at the next start, without a word. Pin it in the one file a per-user config cannot outrank:

keep the listener on loopback, and know what moves it
# /etc/tigervnc/vncserver-config-mandatory
$localhost = "yes";

That file is Perl, so you need the $ and the trailing semicolon. Now restart the session as the user who owns it rather than as root, and read the address back:

keep the listener on loopback, and know what moves it
tigervncserver -kill :1
tigervncserver :1
sudo ss -tlnp 'sport = :5901'

The server comes back on the same display, and the ss line should answer with the same two loopback addresses and no 0.0.0.0.

Bring the session in through an SSH local forward

A vertical sequence of three SSH and VNC commands connected by downward arrows, with the SSH forward highlighted in purple.

From your workstation, open the forward and leave it up for as long as you want the desktop:

bring the session in through an ssh local forward
ssh -N -T -L 5901:localhost:5901 <user>@<server-host>

-N asks for no remote command and -T for no terminal, so the connection carries your forward and nothing else. The localhost in the middle is resolved on the server side, which is what lets it reach a listener bound to loopback. It also holds the terminal for as long as it runs, so take a second one for the viewer:

bring the session in through an ssh local forward
vncviewer localhost:5901

TigerVNC's viewer runs both halves for you, which is less to remember on a laptop you connect from in several places. It builds the forward with ssh before it connects, and the host you name is resolved on the gateway, so localhost:1 still points at the server's own loopback:

bring the session in through an ssh local forward
vncviewer -via <user>@<server-host> localhost:1

Harden the SSH account, because it is now the way in

A flat key approaching a small server with a padlock on its intake port.

Your listener is off the network and your session is encrypted. Everything now rests on who can open an SSH session to that host, which makes sshd_config your VNC security configuration.

Get your key on the server first, while password logins still work, because ssh-copy-id logs in the ordinary way to install it:

harden the ssh account, because it is now the way in
ssh-copy-id <user>@<server-host>

It prints the number of keys it added. Log out, log back in, and watch that it does not ask you for a password. Only then close the password paths, and close both of them: PasswordAuthentication covers the direct prompt, while PAM answers keyboard-interactive logins with a password prompt of its own, and both default to yes.

If you are going to limit logins to a group, create it and put yourself in it before the directive goes anywhere near the file. An AllowGroups naming a group you are not in locks you out at the next restart:

harden the ssh account, because it is now the way in
sudo groupadd --system vncops
sudo usermod -aG vncops <user>

Check id <user> lists vncops, then edit the existing lines in /etc/ssh/sshd_config rather than appending new ones, because sshd keeps the first value it reads for a keyword and ignores the rest:

harden the ssh account, because it is now the way in
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
AllowGroups vncops

Parse the file, read back what sshd will really run with, then restart the unit, which is ssh on Debian and not sshd:

harden the ssh account, because it is now the way in
sudo sshd -t
sudo sshd -T | grep -E '^(passwordauthentication|kbdinteractiveauthentication|pubkeyauthentication|allowgroups) '
sudo systemctl restart ssh

sshd -t checks the file and the keys without touching the running service. The grep should answer passwordauthentication no, kbdinteractiveauthentication no and allowgroups vncops. Keep the session you are sitting in open and prove a fresh login from a second terminal before you let go of it.

Close the VNC range at the firewall

Traffic passes through a firewall panel where OpenSSH reaches allow and the 5900 lane is deflected to deny.

If nothing on the host filters, your bind address is carrying the whole load alone. nftables is the framework everything else sits on in Debian, so one listing covers whatever tool is installed, and rules you wrote with iptables or ufw turn up in it too:

close the vnc range at the firewall
sudo nft list ruleset

Empty output means no packet filtering at all. To put some in, remember that ufw arrives disabled with a default incoming policy of deny, so enabling it shuts the VNC range without you writing a VNC rule, and the OpenSSH application profile that ships with the server package opens 22. Allow SSH before you enable, in this order, or the enable drops the session you are typing in:

close the vnc range at the firewall
sudo apt install ufw
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status verbose

The status listing should show OpenSSH and nothing from 5900 upward.

The password behind the tunnel, and what stops guessing

A small loopback server with five failed-attempt dots beneath it receives a single tunneled connector from one side.

Inside the tunnel your viewer still meets VNC Authentication, and that check truncates the password to eight characters before using it as the DES key. Treat it as a second credential behind the SSH login, never as the thing keeping people out.

Guessing does get answered. Xtigervnc blacklists an address after five failed attempts and refuses it for ten seconds, and that wait doubles each time the same host comes back and fails again.

Here is where it bites you once the tunnel is in place. A forwarded connection reaches the server as a loopback connection, so every attempt arriving through any tunnel is counted against that one address. Five fumbled passwords from one colleague lock the tunnel for everybody on it, and the wait grows from there.

What changes on RHEL 9

A hierarchical diagram of three RHEL 9 settings: the vncserver unit, per-user config path, and firewall port range.

The shape holds, and Red Hat's own advice is to tunnel the VNC connection over SSH. The pieces carry different names:

  • Your unit is vncserver@:<display>, and the display-to-user map lives in /etc/tigervnc/vncserver.users.
  • Per-user options go in $HOME/.vnc/config. The ~/.config/tigervnc path belongs to Debian 13 and TigerVNC 1.14 upward, so a config file you write there on RHEL 9 is read by nothing.
  • firewalld carries a service that opens ports 5900 to 5903 in one go, and a fifth VNC user needs a port above that range opened by hand.

Once the tunnel is your only path in, that firewalld service has no job left. Permanent changes land on the reload rather than straight away, so run both lines together:

what changes on rhel 9
sudo firewall-cmd --permanent --remove-service=vnc-server
sudo firewall-cmd --reload
sudo firewall-cmd --list-services

The listing comes back without vnc-server in it. Then run the same ss check on the RHEL host, because the firewall rule and the bind address are still two different things.

Decide who gets an SSH login on that host. After this sequence that list is the list of people who can open a desktop on it, so keep it to named accounts with keys and prune it the day somebody leaves.

The VNC password goes back to being what it should always have been: a second credential behind a real login, not the lock on the door.

FAQs

Can other users on the same server still reach my session?

Yes. A loopback-bound listener takes connections from the same machine, and anyone with a shell on that host counts as the same machine. Those connections meet the eight-character VNC password and nothing else, because they never go near SSH. Where that matters, the password is your only remaining control, so give each display its own and keep the password file readable by its owner alone.

Does moving VNC off port 5900 help?

Not in any way that survives a scan. The port is 5900 plus the display number unless you set -rfbport, and a listener on 5951 that answers every interface is exactly as reachable as one on 5901. Your bind address decides who can connect; the port number only decides what they type.

Should I use X.509 certificates instead of a tunnel?

Stay with the tunnel when the people connecting already hold SSH accounts on the host, because it adds no new key material for you to manage. X.509 earns its place when viewers need the server without shell access: you issue the server a certificate, change the security types, and put the signing CA on each viewer at ~/.config/tigervnc/x509_ca.pem on Debian 13, or wherever you point -X509CA. Adding those types is the same change that moves your listener back onto the network, so the two decisions are really one.

How do several people share one hardened host?

Give each of them a display and let each open their own forward. Nothing extra has to be opened, because every session arrives on loopback. The alternative, one exposed listener per user, is what forces the RHEL 9 vnc-server range past 5903 and puts every one of those ports back on the network.

community thread

Discuss this in the community

Questions about this, or a setup it does not cover? Ask in Security and Remote Access.

Security and Remote Access group

last active 2 Sep 2026, 11:07