How to install and use Firejail on Linux

Firejail allows you to easily sandbox Linux applications. Find out how to add this extra layer of security.

How to install and use Firejail on Linux

Firejail is a Linux security SUID program that drastically reduces the risk of security breaches by sandboxing the running environment of untrusted applications. Firejail achieves this by using Linux namespaces and seccomp-bpf which allows the attaching of a system call filter to a process and all its descendants, thus reducing the attack surface of the kernel.

With Firejail installed, you can then launch applications from the command line, such that they have a private view of globally-shared kernel resources--such as the network stack. With this addition to your Linux platform, you'll gain a heightened level of security to an already secure environment.

Firejail is not limited to graphical applications. In fact, Firejail can sandbox servers, GUI tools, and even user login sessions. 

Believe it or not, Firejail is incredibly easy to use. I'm going to walk you through the process of installing and using Firejail.

SEE: Mastermind con man behind Catch Me If You Can talks cybersecurity (TechRepublic download)

What you'll need

The only things you'll need to make this work are:

  • A running instance of a Linux platform

  • A user with sudo privileges

I will be demonstrating on Ubuntu Desktop 19.10, but you can make this work on just about any Linux distribution. Since Firejail is found in most standard repositories, you'll only need to adjust the installation instructions to match your distribution of choice.

How to install Firejail

In order to install Firejail, log in to your Linux operating system, open a terminal window, and issue the command (modifying it to fit your distribution package manager):

sudo apt-get install firejail -y

Once the command completes, you're finished with the installation. 

How to use Firejail

Using Firejail is quite simple. Let's say you want to open an instance of Firefox. To do that, go back to the terminal window and issue the command:

firejail firefox

Firefox will open and you'll see quite a lot of output in the terminal window (Figure A).

Figure A


Firefox running in a Firejail sandbox.

You might find that you get no sound from applications sandboxed with Firejail. If that's the case, issue the command:

firecfg --fix-sound

The above command will fix a few bugs in Pulseaudio, so sound should no longer be a problem. After running the command, log out and log back in so the fix can take effect.

If you're using Firejail on a desktop distribution, you'll want to integrate it into the desktop environment (such as GNOME, KDE, Xfce, Pantheon, etc.). To do that, issue the command:

sudo firecfg

Log out and log back in. 

This will configure a number of symlinks, add your user to the Firejail access database, and fix a number desktop files. Once you've run the firecfg command, you no longer have to run your desktop applications from the command line, as they will automatically run using the firejail command.

The caveat and the fix

One issue you might run into is that sandboxed applications won't have access to your filesystem. For example, say you run the command firejail firefox and then attempt to upload a file to a website. Firejail may prevent that. If that's the case, you have to jump through a few hoops to make it work. Here's what you need to do (we'll stick with our Firefox example).

  1. Open up a terminal window.
  2. Issue the command mkdir -p ~/.config/firejail.   
  3. Change into the newly created directory with the command cd ~/.config/firejail.   
  4. Copy the default Firejail profile into the newly created directory with the command cp /etc/firejail/firefox.profile ~/.config/firejail/.    
  5. Edit the newly created profile to suit your needs.

Let's say you need to upload files from the ~/Documents directory. In order to do that, you'll need to add a whitelist entry for that directory. Open the newly created file with the command:

nano ~/.config/firejail/firefox.profile

Under the noblacklist lines, add the following line:

whitelist ${HOME}/Documents

Save and close the file. 

Here's another trick. Say you want to give an application read-only permission to the ~/Documents. For that you could add the line:

read-only ${HOME}/Documents

Save and close the file.

As you can probably surmise, there are a lot of really nifty tricks up Firejail's sleeve. To find out more of what you can do with profiles, issue the command man firejail-profile to read up on what all this feature has to offer.

Also see

computer security


Image: Getty Images/iStockphoto