Fixing Browser Issues as Root & Installing Google Chrome on Debian/Ubuntu

Introduction

I recently set up an XRDP-based Linux graphical interface on my Debian/Ubuntu system. Wanting to debug my npm project in this new environment, I attempted to open a browser to access localhost:5173. However, the default browser wouldn’t launch.

Thinking it was an installation issue, I decided to install Google Chrome, assuming that would fix the problem. But even after installing Chrome, the issue persisted.

Eventually, I realized that the root cause was that I was running everything as the root user, which is restricted from launching graphical applications, including web browsers.


Why Doesn’t the Default Browser Work?

Most browsers on Linux, including Google Chrome and Firefox, enforce security policies that prevent them from running as root. The reasons include:

  1. Security Risks – Running a browser as root poses a significant security risk, as malicious scripts could gain full system access.
  2. X11 Permissions Issues – Graphical applications require appropriate DISPLAY permissions, which are restricted for root.
  3. Sandboxing Enforcement – Modern browsers rely on sandboxing, which is disabled when run as root.

This explains why neither the default browser nor Chrome worked after installation.


How to Fix This Issue

1. Temporary Workaround: Run Chrome with --no-sandbox (Not Recommended)

If you absolutely must run Chrome as root, you can bypass the restriction using:

google-chrome --no-sandbox

Warning: Running Chrome without sandboxing significantly reduces security and is not recommended for long-term use.

2. Proper Solution: Create a Non-Root User (Recommended)

A more secure and recommended approach is to create and use a non-root user for running browsers and other graphical applications.

  1. Create a new user:
   adduser devuser  # Follow the prompts to set a password
  1. Grant the user necessary permissions:
   usermod -aG sudo devuser
  1. Switch to the new user:
   su - devuser
  1. Run your browser normally:
   google-chrome

Using a normal user ensures that your system remains secure while allowing browsers to function correctly.


Installing Google Chrome on Debian/Ubuntu

If Google Chrome is not installed, follow these steps:

1. Download the Chrome Installer

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

2. Install Chrome

sudo dpkg -i google-chrome-stable_current_amd64.deb

If there are missing dependencies, fix them with:

sudo apt --fix-broken install -y
sudo dpkg -i google-chrome-stable_current_amd64.deb

3. Verify Installation

Check if Chrome was installed correctly:

google-chrome --version

4. Set Chrome as the Default Browser

xdg-settings set default-web-browser google-chrome.desktop

5. Open a URL in Chrome

xdg-open http://localhost:5173

If the above command still fails due to root restrictions, ensure you switch to a normal user before running it.


Conclusion

At first, I thought my browser issues were due to a missing installation, so I installed Google Chrome, only to find that the issue persisted. The real problem was running everything as root, which Linux security policies prevent for graphical applications.

To resolve this, you can temporarily use --no-sandbox, but the best approach is to create and use a normal user. This ensures proper browser functionality while maintaining system security.