
Run Firefox on a VPS Using X11 Forwarding via SSH
When using a Virtual Private Server (VPS), you may want to run graphical programs like Firefox without the need for a full desktop environment to be installed. X11 forwarding with SSH allows you to run graphical programs remotely and have them display locally, without the cost of a full desktop environment.
This guide will guide you through X11 forwarding setup and installing Firefox onto a VPS, all steps required both server and client. It will also show the necessary configuration in different operating systems, including Linux (Ubuntu/Debian, CentOS/Red Hat, SUSE), macOS, and Windows.
Prerequisites
VPS with SSH access enabled and configured.
Client machine with SSH support and X11 forwarding capabilities (Linux, macOS, or Windows).
Firefox installed on the server (you need to install Firefox on the VPS).
Basic familiarity with using the terminal.
What is X11 Forwarding?
X11 forwarding is one way to get graphical applications on a remote server and see their graphical output locally over an SSH connection. What we're going to do now is run Firefox on the VPS and make its graphical interface appear locally.
Step 1: Install Required Packages
On the Client Side (Local Machine)
For your local machine to display graphical applications forwarded from the server, you'll need the necessary software to support X11 forwarding.
Linux (Ubuntu/Debian, CentOS/Red Hat, Fedora, SUSE)
For Ubuntu/Debian, CentOS/Red Hat, Fedora, and SUSE, the required packages are:
xorg
xauth
openssh-client
Installation commands on Linux:
Ubuntu/Debian:
sudo apt update
sudo apt install xorg xauth openssh-client
CentOS/Red Hat/Fedora:
sudo yum install xorg-x11-server-Xorg xauth openssh-clients
For Fedora, use dnf
instead of yum
:
sudo dnf install xorg-x11-server-Xorg xauth openssh-clients
SUSE:
sudo zypper install xorg-x11 xauth openssh firefox
On macOS
On macOS, X11 support is managed by XQuartz, an X11 server for macOS.
Download and install XQuartz from here.
After installing, launch XQuartz to enable X11 forwarding.
Alternatively, if you use Homebrew, you can install it directly:
brew install --cask xquartz
On Windows
For Windows, you can use VcXsrv or Xming as an X11 server.
VcXsrv:
Download and install VcXsrv from SourceForge.
During installation, select "Start no client" and start VcXsrv after installation.
Xming:
Download and install Xming from SourceForge.
Install and run Xming.
Step 2: Install Firefox on the VPS (Server-Side)
To run Firefox on the VPS and forward its graphical interface to your local machine, you need to install Firefox on the VPS.
Install Firefox on the VPS:
Ubuntu/Debian:
sudo apt update
sudo apt install firefox
CentOS/Red Hat/Fedora:
sudo yum install firefox
For Fedora:
sudo dnf install firefox
SUSE:
sudo zypper install firefox
Step 3: Install and Configure OpenSSH on the VPS (Server-Side)
If you haven't already done so, you need to ensure that OpenSSH Server is installed and properly configured to support X11 forwarding.
Install OpenSSH on the VPS:
Ubuntu/Debian:
sudo apt update
sudo apt install openssh-server
CentOS/Red Hat/Fedora:
sudo yum install openssh-server
For Fedora:
sudo dnf install openssh-server
SUSE:
sudo zypper install openssh
Step 4: Configure the SSH Server for X11 Forwarding
To enable X11 forwarding, you must modify the SSH server configuration on the VPS. Follow these steps:
Edit the SSH configuration file:
sudo nano /etc/ssh/sshd_config
Enable X11 forwarding by adding or modifying the following lines:
X11Forwarding yes X11UseLocalhost yes
X11Forwarding yes
: Enables X11 forwarding.X11UseLocalhost yes
: Ensures the server uses localhost for X11 forwarding.
Restart the SSH service to apply the changes:
sudo systemctl restart sshd
Step 5: Connect to the VPS via SSH with X11 Forwarding
Now that your server is set up, you can connect to it from your local machine and use X11 forwarding.
On Linux/macOS:
Run the following SSH command to connect with X11 forwarding enabled:
ssh -X username@ip_vps
For less restrictive forwarding, use the -Y
option:
ssh -Y username@ip_vps
On Windows (using PuTTY):
Open PuTTY and enter the VPS IP address.
In the sidebar, navigate to Connection > SSH > X11.
Check the box for Enable X11 forwarding.
Click Open to start the SSH session.
Step 6: Verify X11 Forwarding
Once you're connected to the VPS via SSH, you can verify that X11 forwarding is working by checking the DISPLAY
environment variable.
Run this command:
echo $DISPLAY
If X11 forwarding is correctly configured, the output should look like:
localhost:10.0
If nothing is returned, X11 forwarding is not enabled correctly.
Step 7: Run Firefox via SSH
Now that you've successfully connected to the VPS with X11 forwarding, you can run Firefox remotely on the VPS, and it will display on your local machine.
To launch Firefox on the VPS, use the following command:
firefox
Firefox will run on the VPS, but its graphical interface will be displayed locally on your machine, just like it was running natively on your system.
Troubleshooting
The DISPLAY Variable is Empty
Ifecho $DISPLAY
returns nothing, it indicates X11 forwarding isn't working properly. Verify the following:The
/etc/ssh/sshd_config
file on the VPS containsX11Forwarding yes
.The X11 server (XQuartz on macOS, VcXsrv/Xming on Windows) is running on your local machine.
You've connected to the VPS using the
-X
or-Y
option for SSH.
Firefox Error Messages
If Firefox doesn't start, check the error messages in the terminal. You may need to install additional libraries or adjust permissions on the server.Firewall or Network Issues
Ensure that the firewall on the VPS does not block X11 traffic. Make sure that port 6000 (used by X11) is open.
To wrap up
From this tutorial, you are now aware of how to allow X11 forwarding on a VPS and run graphical applications like Firefox remotely without the need to install a full desktop environment. This method reduces resource usage on your VPS while allowing you to run graphical applications securely from your local machine.
This method comes in handy when it comes to reducing resource usage on your VPS while still providing access to graphical applications.