How to easily add a context menu item that enables a Linux user to open files as root or administrator via right mouse click when browsing a file system. This feature allows the user to navigate their file system and open or edit any file or directory as the root user or admin of the system. It is a great solution for those that are not completely comfortable using terminal commands.
Note: The following process assumes you're using a Debian based system with nautilus. Ubuntu and other Debian based remixes should also work. An Ubuntu Linux Live USB was used in the example here. If you follow along from a fully extracted Linux installation, you will need to make sure you add user to sudoers before proceeding.
You’ll need to make sure you have the universe repository enabled because "nautilus-admin" is not available from standard repositories.
Security Warning: Running files or editing system files as root can be dangerous. It is important to be cautious while using this feature, as making unintended changes to system files could render your system unstable or cause irreparable damage. Always double check the files you are working with and make backups of critical files before making changes.
Add a menu to Right Click Open Files as Root
To add a contextual menu item that enables you to Open files as Root or Administrator with a simple right mouse click:
- Open the Terminal Ctrl + Alt + T
- Type sudo su and press enter.
- Provide your password and press enter.
- Then type apt install -y nautilus-admin and press enter.
- Now type nautilus -q and press enter.
- Finally, type exit and press enter, then close the terminal window.
Right Click Open Files as Administrator
To open a file as root, simply right-click the folder and select Open as Administrator
Pro Tip: If the file manager was already open while you installed nautilus-admin, you'll need to close and reopen it to see the changes. If that doesn’t work, simply log off and then log back in to see the changes!
You now also have the option to edit files as Administrator using a right-click.
Troubleshooting
In case the context menu doesn’t appear or you face issues after installation, here are some tips:
- Missing Menu Option: If the "Open as Administrator" option doesn’t show up, try restarting your file manager by typing nautilus -q in the terminal or simply log off and log back in.
- File Permissions: Be careful when opening files as root. If you accidentally modify critical system files, it can lead to instability or issues with your system. Make sure you know what you’re modifying.
Alternative File Managers
If you are using a file manager other than Nautilus (such as Thunar or Dolphin), this process might differ slightly. You'll need to search for a similar package or plugin for your file manager that enables you to run files as root via the context menu. For example, in Thunar, you can install the thunar-archive-plugin for administrative privileges.
Alternatives to Context Menu Editing
If you're not a fan of adding the "Open as Administrator" option directly to your context menu, there are alternative methods such as using gksudo or pkexec for specific tasks that require root privileges. These tools open a graphical prompt for entering a password and then run a command with administrator access.
Further Reading
If you are new to using the sudo command or managing file permissions in Linux, it’s a good idea to familiarize yourself with some basic concepts. Here are a few resources you can explore:
- Understanding Sudo on Linux
Final Thoughts
In this guide, we've shown how to easily add a right-click context menu option in Linux to open files as root or administrator, streamlining the process for users who prefer not to use terminal commands. By following simple terminal steps, users can gain quick access to file management with elevated privileges, making it easier to modify system files or perform administrative tasks. We’ve also included troubleshooting tips, security warnings, and resources for further learning, ensuring users are prepared to safely use this feature. Whether you're using Nautilus or another file manager, this guide provides helpful insights and alternatives to improve your Linux experience.