I found a (lengthy) guide to doing this but it is for gksu which is gone. I have to imagine there’s an easy way. I am running Ubuntu. There is no specific use case, it is just a feature I miss from windows.

EDIT: I always expect a degree of hostility and talking-down from the desktop Linux community, but the number of people in this thread telling me I am using my own computer that I bought with my own money in a way they don’t prefer while ignoring my question is just absurd and frankly should be deeply embarrassing for all of us. I have strongly defended the desktop Linux community for decades, but this experience has left a sour taste in my mouth.

Thank you to the few of you who tried to assist without judgement or assumptions.

  • Do not do this. “Run as Administrator” is a Windows answer to a Windows problem. The only time you should regularly need root privileges is installing software and editing system wide configuration files.

  • I do not really see hostility or taking down. More of a difference of opinion or experience.

    Also, this is not a private email thread. It is a public forum. Whatever advice you get risks becoming guidance for the community. I think it is perfectly reasonable, even responsible, for people to respond with their thoughts on security.

    You can ignore the advice not to implement this capability on your personal machine. That is your call. However, this should not become standard practice by Linux users.

    Thank you for answering at some point in the thread the use cases that drove your question. I was very curious.

    When I have needed “Run as Administrator” in Windows, it has typically been to run the command line. The reason Windows needs this is because it has lacked “sudo”. The next release of Windows is adding it as a feature ( going the other way ).

    I have used Linux for decades as well and really not needed this. Partially this is because tools that require root access are typically configured to ask for it already.

    Your “need to delete a file” use case made sense to me but I do not run into it. Perhaps my file systems are mounted differently. Perhaps I am not manipulating files of other users ( sounds right ). Or maybe I am more likely to be at the command line. Your “edit files as root” use cases leads me to believe I use the command line more as that is certainly something I would be doing from the terminal. I have to edit files as root everyday but it is always from the terminal. I am not encountering files that I cannot edit in my file manager though as I would have navigated to those files in the terminal to begin with. Clicking around in a file manager to get to system files is not even something that would have occurred to me. If I am using the file manager, it is to manage my own files ( mostly media and documents ).

    No judgement. Do things how you want. I was just curious what you were using this for. When I use Windows, I use “Run as Administrator” all the time. In Linux, I did not even notice it was missing. Going back to Windows makes me miss “sudo” in the terminal though. I am not the only one obviously as they are now adding it to Windows too.

    • The default, nautilus.

      “Run as Adminstrator” in the context menu is a default feature in Windows. It seems odd I’m the first person to want this in Linux.

      • It is rare that you would want to run an entire GUI program as root, and if it is needed, the program should prompt you for it. Do you have a specific use case where you need to do that regularly?

          • Not necessarily a satisfactory solution for you, but the usual way to handle that is just using a text editor in the shell with sudo, like nano or vim. It’s pretty fast and easy once you get used to it. I don’t know if there are any good graphical ways of doing it.

            • I know. That’s what I’ve been doing for years. I could also just sudo gedit file directory filename but it’s SO much easier to right-click “open as admin” which is why I asked.

              • I would suggest right-click in the folder in your file explorer -> open in terminal -> sudo nano autocomplete file name (tab tab). At least to me that doesn’t seem that much more involved and is safer. Otherwise, as others have noted, there are apparently ways of doing what you want, but it is discouraged for good reasons.

      • That’s not how that should work. You also shouldn’t need that in Windows either.

        Programs that need Admin rights will ask for it. There are a fee limited cases but most of the time it creates more problems than it solves.

        From your comments I’ve read it sounds like there is more to this story. Can you share what you are trying to do? On gnome gnome disks can run fine under the user. It will elevate when it needs to and it is designed with least privilege.

        For file shares root is pretty much meaningless in most contexts. If you don’t have access you don’t have access as authentication is handled server side. If you setup a automatic mount check your mount options as you can set it to be owned by the local user. Also if you mounted the share in a graphical file utility such as nautilus it will be mounted for the local user so you will not need root.

        Root should be used very sparingly. It is not the same as Admin on Windows. It is almost equivalent to the SYSTEM user on Windows.

  • For context, I answered this after your edit. First, I don’t know how to add another context menu on a file manager, but I imagine if there is a way to do that, there is a command to be run when doing it. Hence, what I will answer is only the command.

    For editing a file, you absolutely don’t need to open the editor as root. You can however, make a temporary copy of a file that your own user has access to, edit those temporary files, and when you are done editing it just replace the old file. This is what sudoedit FILE does.

    Secondly, for manipulating a file, I agree with the other commenter that it still is a bad practice to run the file manager as root. Instead, try to add a context menu for taking ownership of a file/folder recursively. chown does exactly that. Of course chown won’t save you if that file is a network mount with some form of other access control.

    Third and last, yes I agree that if a user wanted to nuke their installation it is their right to do so. However, do remember that this is also a forum and that we always remind each other the best practice since maybe another user will stumble upon this and think “oh, this is how it is in Linux”. We do not have the equivalent of “Run as Administrator” here in linux as that would mess up a lot of assumptions for other programs and easily make the system unstable or outright unusable.

  • That’s not a good idea as root isn’t the same as an Administer account. Also, you might want to consider why you are running programs as root. You may have a chicken and the egg problem.

    Maybe step back and give us some more context.

  • This is very easy in KDE but Desktop entries work the same on all Desktops.

    See this post where I mentioned how to do this with running Konsole with root.

    In general, use polkit instead of sudo, every desktop has a GUI dialog that pops up.

    pkexec APPNAME
    

    And add this as a desktop action, following the guide.

    [Desktop Entry]
    Type=Application
    Exec=konsole
    Icon=utilities-terminal
    Categories=System;TerminalEmulator;
    Actions=root
    Name=Konsole
    GenericName=Terminal
    Comment="$GenericName"
    
    [Desktop Action root]
    Name=root
    Icon=folder-root-symbolic
    Exec=pkexec konsole
    

    In the specific case of Konsole you could use a profile instead.

    Be aware that nearly no program should be ran as root. Also not Konsole. The program is ran as the user, and can enter a root shell, but never run random apps as root. Not even many terminal apps are made to be ran as root, for example use sudoedit instead of sudo nano for editing files.

    To view and change system files in KDE, type admin:/ into the location bar.

    Running apps as root doesnt work with Wayland, and for a good reason.

    • I think the talking down aspect comes from phrases like “you shouldn’t be doing X”, especially when these statements are made as absolutes, rather than contextualised with actual reasons.

      Running GUI programs as root might cause security problems, or it might cause software problems. And while you might find these issues important, others might not.

      In my opinion, saying something like “it’s not a good idea if you care about security” or “doing so might make your PC burst into flames” gives helpful warnings for OP and future readers without talking down to them by making decisions for them what they should and should not do.