Introduction
Have you ever tried launching a graphical application with sudo on Wayland? I recently ran into a common Wayland problem: I couldn’t use a GUI text editor to edit a protected configuration file. On my setup attempting to launch graphical applications with elevated privileges did not work and only generated errors and warnings. It’s one of multiple Wayland-related issues I’m seeing and trying to find practical workarounds.
I understand the security concerns around running graphical applications with administrator privileges. Still, when a GUI editor can’t access a protected file, users generally have no choice bu to turn to command-line tools, even for simple configuration changes.
Without a convenient graphical option, users will end up doing more work from the command line than they’re comfortable with. This increases the chance of mistakes, especially when editing system files. This basically knocks the legs out from under the argument for limiting GUI application’s elevated permissions.
What I want to do here is find a practical workaround that lets average users edit protected configuration files without resorting to the command line.
The major desktop environments (KDE Plasma, Gnome, XFCE, etc) tend to provide their own administrative tools, but not everyone uses a major desktop. In this video, I’ll explore a workaround that should also be useful on other minimal setups.
For context, I’m using a system I built and documented in earlier articles: a base Arch Linux installation on a Btrfs filesystem, using the Labwc Wayland compositor, and greetd Display (login) manager. I’m also using PCManFM-Qt as my file manager and Geany as my text editor.
The option I will be using is sudoedit, which takes a different approach from launching the editor itself with administrator privileges. It lets you edit a temporary copy of the protected file as a regular user, then applies the changes to the original file with elevated privileges. That makes it a promising option for editing system configuration files with a graphical editor.
The exact behavior can and will vary depending on the application, compositor, and system configuration. I’m describing how it works on my setup; your experience and the usability of this approach may differ.
Avoiding the Wayland Restriciton
Looking at my file tree, lets suppose I want to edit the greetd configuration file at /etc/greetd/config.toml. Its permissions are 0644: the owner can read and write it, while the group and everyone else can only read it. Since both the owner and group are root, I need elevated permissions to make changes.
On my trusty old X11 setup, I could run sudo geany /etc/greetd/config.toml, edit the file, and be done. On my current Wayland system, trying to launch Geany that way produces permission and display-access errors. So I’ve been falling back to the command line with sudo nano /etc/greetd/config.toml.
Today, instead, I’m going to add a custom action to PCManFM-Qt. Custom actions appear in the file manager’s right-click menu, and their desktop-entry files belong in ~/.local/share/file-manager/actions/. I’ll also create a script in ~/.local/bin for the action to run.
The script will set geany as the editor and call sudoedit on the selected file. This way, geany itself doesn’t need administrator privileges.
Pcmanfm-qt Custom Actions
PCManFM-Qt supports custom actions that appear in the right-click menu. Each action is defined in a .desktop file. Since this action will be used to edit protected configuration files, I want it to be available only to my user. I’ll store the file in PCManFM-Qt’s user-specific actions directory: ~/.local/share/file-manager/actions/. If the required directory does not exist, I can create it and any missing parent directories with:
mkdir -p ~/.local/share/file-manager/actions/
Because this directory is inside my home folder, I don’t need sudo. Next, I’ll create the .desktop file in that directory:
nano ~/.local/share/file-manager/actions/geany-sudoedit.desktop
Now I can start adding the action’s configuration.
The .desktop file
The first section defines the custom action:
[Desktop Entry]
Type=Action
Name=Edit as administrator
Icon=geany
Profiles=profile-zero;
PCManFM-Qt uses Name as the label shown in the context menu and Icon as the icon name. If the current icon theme doesn’t include a Geany icon, you can specify an icon file’s full path instead. Profiles points to the action profile defined below. The next section defines what the action does:
[X-Action-Profile profile-zero]
SelectionCount==1
MimeTypes=all/allfiles;
Exec=/home/rt/.local/bin/edit-as-admin %f
Name=Default profile
SelectionCount==1 makes the action available when exactly one item is selected. MimeTypes=all/allfiles; makes it available for files of any type. The Exec line runs the edit-as-admin script and passes it the selected file’s path using %f. Replace /home/rt with the path to your own home directory if needed.
The profile’s Name is optional; it’s a label for the profile, not the text shown for the action in the context menu. Also, make sure the key is spelled MimeTypes, with an s.
For initial testing, I’m allowing the action to appear for all files. That’s convenient, but it may also show up for files that aren’t suitable for editing. Once testing is complete, I can narrow the match to the file types I want. text/plain is one possible MIME type, but not every configuration file is identified that way.
Because this action can edit files with elevated privileges, the script is the most important part to review for safety. The .desktop file launches the script; it doesn’t decide how the script obtains elevated privileges or handles the selected path.
The Script
First, I’ll create a directory for my user’s scripts, if it does not exsit:
mkdir -p ~/.local/bin
I’ve used /usr/local/bin for scripts in other videos, but that directory is generally for software installed system-wide. This script is specific to my user, so ~/.local/bin is a better fit. The XDG Base Directory Specification allows user-specific executable files to be stored there. Since the .desktop file will call the script by its full path, it doesn’t need to be on my PATH. Next, I’ll create the script:
nano ~/.local/bin/edit-as-admin
#!/bin/bash
file="$1"
# If the file writable by user – No Admin
if [ -w "$file" ] && [ -w "$(dirname -- "$file")" ]; then
exec /usr/bin/geany -i "$file"
fi
# Otherwise, use sudoedit from a foot terminal.
exec foot sh -c '
SUDO_EDITOR="/usr/bin/geany -i" sudoedit "$1" || {
printf "\nEditing failed. Press Enter to close..."
read -r _
}
' sh "$file"
There are a couple of things worth explaining. First, the script checks whether both the file and its containing directory are writable by the current user. If they are, it opens the file directly in Geany. Otherwise, it launches sudoedit inside a foot terminal, where sudo can prompt for a password if needed. sudoedit runs the editor as the regular user on a temporary copy, then applies the changes to the protected file.
The final sh in the foot command is a placeholder. With sh -c, the first argument after the command string becomes $0, and the next becomes $1. The placeholder means the filename is passed as $1, where the script expects it. Without the placeholder, the filename would become $0, and I’d need to change the script to refer to $0 instead.
Finally, I’ll make the script executable:
chmod +x ~/.local/bin/edit-as-admin
Testing
With the setup complete, I’ll restart PCManFM-Qt and test the action with two files. First, I’ll select a file in my home directory. Since I can write to both the file and its parent directory, the script should open it directly in Geany. Then I’ll select a root-owned file under /etc to test the sudoedit path. For the initial test, the desktop entry uses:
MimeType=all/allfiles;
This makes the action available for all files, so I’ll keep in mind that the action may appear for file types that aren’t suitable for editing. After testing, I’ll narrow the MIME-type list. PCManFM-Qt supports multiple MIME types, separated by semicolons. Foe example;
MimeType=text/plain;application/json;application/yaml;application/xml;
This covers some common text and structured-data formats, but it isn’t exhaustive. I may need to add other MIME types as I use the action. Also, the MIME type assigned to a file can vary across systems, so a configuration file might not be recognized as text/plain.
One important point about the /etc test: sudoedit uses elevated authorization to write the changes back to the protected file. Geany itself runs as my regular user—that’s the key difference from launching Geany with sudo.
Conclusion
This gives me a convenient way to open files from PCManFM-Qt without launching Geany as root. For files I can already edit, the script opens them normally. For protected files, sudoedit handles the privileged write-back while Geany runs as my regular user.
This setup works on my Labwc system, but the details may differ on other desktops, file managers, or configurations. The custom action can also appear for files that aren’t appropriate to edit, so I’ll narrow the MIME types and check the selected file before making changes. As with any tool that can modify system files, it’s worth understanding what the script does before using it.
For my setup, this is a useful alternative to editing system files directly in the termina, and it avoids running the whole graphical editor with administrator privileges.



Leave a Reply