Ubuntu Security: Using Firejail to Sandbox Applications and Prevent Data Theft

Ubuntu tutorial - IT technology blog
Ubuntu tutorial - IT technology blog

Vulnerabilities from Complacency: When a “Standard User” Isn’t Safe Enough

When I first started “tinkering” with Ubuntu, I believed Linux was an impenetrable fortress. I freely downloaded scripts from GitHub and installed various tools without a second thought. But reality is much harsher: any small script running with standard user privileges can read all the data in your /home directory.

Imagine this: You download a new video player. You think it only needs to read MP4 files? In reality, if left unchecked, it could silently rummage through your .ssh folder to steal your Private Keys. It could also easily copy browser configuration files containing passwords or turn on your webcam without you ever knowing.

The Root of the Problem: Why is Linux So “Generous” with Permissions?

It all comes down to the default permission model. When you run an application as the user itfromzero, that app inherits all your permissions. It has the right to read and write to every file you own. This mechanism helps software work together easily, but it’s a fatal flaw if the application contains malware.

Most of us worry about installing Firewalls or Fail2ban for servers. We forget that the Workstation is often the primary target. If a personal machine is compromised, the attacker gains a “master key” to infiltrate every other critical system you manage.

Sandboxing – Balancing Security and Performance

Before discovering Firejail, I struggled with several cumbersome options:

  • Virtual Machines (VM): Absolutely secure, but they consume 2-4GB of RAM just to run a small tool. Waiting for a VM to boot was enough to kill my productivity.
  • Docker: Great for backend services, but running GUI applications is a major hassle, often resulting in font or audio issues.
  • AppArmor/SELinux: Extremely powerful, but writing profiles for them is a true challenge. A single misplaced semicolon can cause an application to crash instantly.

After much experimentation, I found Firejail. It is a “feather-light” solution for isolating applications on Ubuntu.

Implementing Firejail: Creating a Secure “Cage” for Applications

Firejail leverages built-in Linux kernel features like Namespaces and Seccomp-bpf. It creates a virtual environment (Sandbox) around the application. Inside this cage, the app only sees a simulated system with an empty home directory. It can’t see real files, can’t access the network (if restricted), and cannot interfere with other processes.

Step 1: 30-Second Quick Install

Firejail is available in the default Ubuntu repositories. Just open your Terminal and run:

sudo apt update
sudo apt install firejail firetools -y

In this command, firejail is the execution tool, while firetools is a graphical interface that lets you visually monitor “caged” applications.

Step 2: Running Applications Safely

The simplest way to use it is by prefixing your launch command with firejail. For example, to browse the web safely with Firefox:

firejail firefox

At this point, Firefox will still run smoothly. However, if you try to use the browser to open a file in ~/.ssh, the system will immediately return a “file not found” error.

Step 3: “Hardened” Security Modes

Depending on the software’s trustworthiness, I often use the following options:

1. Private Mode (Trace-free Browsing):

firejail --private firefox

This command creates a temporary home directory in RAM. All downloads, browsing history, and cookies evaporate as soon as you close the browser. No traces are left on your hard drive.

2. Network Sandboxing:

For offline image viewers or video editors, I always block internet access to prevent any stealthy data transmission:

firejail --net=none vlc

3. Read-only Mode:

If you want an application to be able to view but not modify important documents:

firejail --read-only=~/Documents my_app

Automation with Firecfg

You certainly don’t want to open the Terminal and type commands every time. Use firecfg to integrate Firejail into your entire application menu:

sudo firecfg

After running this, every time you click the Firefox or VLC icon on your screen, they will automatically run within the Firejail sandbox. Extremely convenient!

Conclusion from Real-World Experience

Security isn’t about installing a ton of antivirus software; it’s about building good habits. Firejail has almost no performance overhead (much lower than a VM). In return, it provides absolute peace of mind when working with unfamiliar tools.

Don’t put blind faith in every script you find online. Make it a habit to sandbox them. This is the best way to protect your SSH keys, bank accounts, and work secrets. Install Firejail today—your system will thank you for it.

Share: