Add ‘Open File/Folder as Root / Administrator’ in Elementary OS 6 [Update 2021]

This is a step by step tutorial shows how to add “open as root (or administrator)” option in Pantheon file browser in Elementary OS 6 Odin.

Elementary OS now is at version 6.0 based on Ubuntu 20.04 LTS. For those looking for the “Open as Administrator” function to open system file via root user permission, or do copy & paste things outside of user’s home directory, things have changed.

The executable command for the file manager now is io.elementary.files, and the command to start text editor is io.elementary.code. Both are named in Flatpak app style. Gksu has gnone, and “pkexec” takes the place to allow an authorized user to execute program as root.

Add Open as Admin action in Elementary OS 6:

1. ) Firstly, search for and open “terminal” from the top-left corner Applications menu.

2. When terminal opens, run command to create (& edit via nano) the configuration file for option to edit file as root user privilege:

sudo nano /usr/share/contractor/io.elementary.code.open-as-root.contract

When the file opens in terminal, paste following lines and save via Ctrl+X, type y and hit Enter.

[Contractor Entry]
Name=Edit as Administrator
Icon=io.elementary.code
Description=Edit file via root user privilege
MimeType=text/plain;
Exec=pkexec io.elementary.code %U
Gettext-Domain=code

3. And create another config file for an option to open folder as root permission:

sudo nano /usr/share/contractor/io.elementary.files.open-as-root.contract

Then paste the following lines and save it (Ctrl+X, type y, and hit Enter):

[Contractor Entry]
Name=Open as Administrator
Icon=system-file-manager
Description=Open a folder via root user privilege
MimeType=inode/directory;
Exec=pkexec io.elementary.files %U
Gettext-Domain=file manager

After creating the two files, “Edit as Administrator” and “Open as Administrator” context menu option appear when right-clicking a file or folder immediately without restart.

As you see, you can create more actions by creating files with “.contract” extension under /usr/share/contractor directory. The name will be displayed as menu option, and you can find value of icon, MineType and Exec by checking the app shortcut file (.desktop) under /usr/share/applications directory.

That’s all. Enjoy!