Is there a way to add "Run as Sudo" to context menu like with Windows?

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.

KaninchenSpeed ,

I'm assuming you're using the nautilus file manager.
I found this post in adding right click actions to nautilus: https://askubuntu.com/questions/210192/how-can-you-add-an-item-to-the-right-click-menu-in-nautilus-without-nautilus-ac#672553
You could make a bash script like shown in the post and use polkit to open the password prompt and run a command as root.

TurboHarbinger ,

Other threads:

You are free to do anything and everything with Linux!

ITT:

YOU CAN'T DO THAT

ikidd ,
@ikidd@lemmy.world avatar

I don't know why everyone is getting self-righteous about this. I've used Linux since the mid-90s, and occasionally I find it easier to just run a GUI file manager as root to do some filter and deletions of things in caches and such that need root permission. Hell, I want to edit the files in /etc/wireguard for my tunnels; should I only do this at a sudo prompt in the terminal when I'm perfectly capable of pulling it up in Kate and copypasting stuff in?

Get off your high horses, there's plenty of valid use cases if you're using your head.

rickyrigatoni ,
@rickyrigatoni@lemm.ee avatar

Manipulating large amounts of different files in terminal is a pain in the ass and everyone who disagrees is wrong.

sorrybookbroke ,
@sorrybookbroke@sh.itjust.works avatar

Don't know about gnomes default file manager, but dolphin has this ability. You'll have to install the addons and enable it in the context menu however.

To repeat others opinion though, I haven't actually needed this feature outside of very specific situations (that I create myself). Linux operates a bit different and shouldn't need this for anything outside of some poorly made, or potentially malicious apps and scripts. I agree though it's still nice to have the option

bitfucker ,

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.

possiblylinux127 ,
@possiblylinux127@lemmy.zip avatar

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.

LeFantome ,

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.

recarsion ,

I see no "hostility" and "talking down" here. You shouldn't be running GUI programs with sudo, and the fact that you've been using Linux for X amount of years doesn't change that.

Kacarott ,

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.

boredsquirrel , (edited )

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.

flork OP ,
@flork@lemy.lol avatar

Thanks for this, but I have a question:

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

Are you sure about this? I run GUI apps as root all the time and have Wayland.

boredsquirrel ,

Not sure if all apps, maybe some work, maybe they use XWayland. Dont do this.

ouch ,

There is a lot of advice in this thread warning you about doing this. Please heed it. Instead, read more about how permissions and file ownership works.

flork OP ,
@flork@lemy.lol avatar

I appreciate the absolute mountains of concern that I am using my own computer incorrectly, but I've been doing it this way for more than a decade and have never once broken anything, lost data or exposed myself to a security risk so I think I'm doing ok.

possiblylinux127 ,
@possiblylinux127@lemmy.zip avatar

You are absolutely not. It really bad practice. I can not state that enough.

Practice least privilege

I'm not trying to offend you. I just want to help.

konidia , (edited )

Emacs can let you edit root files using TRAMP

There's also YaST , but that's an OpenSUSE thing.

nik282000 , (edited )
@nik282000@lemmy.ca avatar

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.

Revan343 ,

It would occasionally be handy running gparted, but for as often as I need to do that sudo gparted works just fine

nik282000 ,
@nik282000@lemmy.ca avatar

I've seen people say that a few times here but any time I use gparted I get the Gnome 'enter password' dialog which seems to work fine.

Revan343 ,

I'm not on Gnome, variably either Xfce or LxQt, is probably what's making the difference there

teawrecks ,

Sounds like you need to install polkit for the window manager you're using (xfce-polkit or lxqt-policykit on arch). That should enable apps to request root using the login popup.

possiblylinux127 ,
@possiblylinux127@lemmy.zip avatar

Gparted prompts you to enter your password so it can elevate itself to root.

Nibodhika ,

Sudo is "su do", i.e. "run as root", so it's funny to hear run as sudo because it means "run as run as root", like "chai tea" or "ATM machine".

To your question the answer is "why?". You shouldn't need that, that's one of the hardest things to get rid of, the "Windows mentality", it's like when people ask how to install a .tar.gz they downloaded from the internet, the answer is most likely "you don't need that".

This leads to an XY problem, where you're asking how to solve problem Y but that is caused by you assuming you need to do X, when in fact you don't. The main clue is that people keep asking you why do you want to do this. So, what exactly is the problem you're trying to solve? Why do you think you need this?

flork OP ,
@flork@lemy.lol avatar

There is no reason to assume this is an XY problem scenario.

Nibodhika ,

Yes there is, you're asking how to add a menu entry to run things with sudo, and refuse to answer why you want to do it, what's your use case? What graphical application do you need to run with sudo and why?

I'm almost sure I know why, and your refusal to answer this even though it's been asked multiple times seems fishy. Like it was explained multiple times there's a 99% chance that you don't need it, and there is a package for the remaining 1% or you could do it manually like others have suggested. But until we know your use case we can't help you, so while you keep refusing to explain what is it that you're actually trying to accomplish and why do you feel you need it it will be impossible for anyone to help you.

flork OP ,
@flork@lemy.lol avatar

What I want to accomplish is to open files and programs as root without use of the terminal. I promise you I have no nefarious intentions towards you or your ilk.

Nibodhika ,

What program? What files? Why do you need to run them with sudo? You're either being purposefully vague or you don't even know why you think you need this.

flork OP , (edited )
@flork@lemy.lol avatar

The question is not about a specific use-case, but a general one. An alternative reading would be "Is there a way to run short commands as root without switching to the terminal?"

inetknght ,

I have had to un-teach dumb things that people learn from Windows.

A menu item to run a GUI program as root it is indeed a rather absurd scenario. It suggests that you want to violate the admin/user barrier which is intended to be difficult to surpass except in certain circumstances.

There can be a lot of things under the hood that are necessary to run a GUI program as root depending on whether you're using X11 or Wayland or something more esoteric. It's doable though.

But instead of doing that, why not just learn how to use the command line? Every administrative task can be done via the command line, but not every administrative task has a GUI counterpart. So you're going to need to learn to use the command line sooner or later.

desconectado ,

OP asks a relatively simple question, and gets scolded as it committed murder.

For all we know OP is the only user and is just playing with Linux, and just wants a simple (probably unnecessary) shortcut because he's GUI oriented.

This is kind of someone asking how to open their lunchbox easier, and get treated like they are giving a copy of their house keys to everyone in town.

Chill... Not everyone is running a maximum security level server. If OP screws their system (like most of us do at some point), I'm sure a fresh re-install would be enough for them.

Nibodhika ,

It's a relatively simple question, but it's a loaded question, it's like someone asking you how you run "apt-get upgrade" on Windows, the question implies that this is possible and necessary, the correct answer to any such question is "what is it that you're trying to accomplish? Why do you think you need this?". 99% of the times the answer is that the person is trying to do something else entirely, this is known as the XY problem, the person has problem X and is asking how to solve problem Y that he's having because he thinks that's the only way to solve X.

In OP's case he caused the issue by running one program as root, and then everything that program touched needs root now, so he needs to run things as root because he's running things as root, it's a cyclical problem, if he had never ran things with sudo he wouldn't need to run things with sudo. Everyone was asking him why he feels he needs that and he wasn't answering, in one answer he let it slip his original mistake that caused all of this headache.

Yes, the community can be a bit toxic sometimes, but if everyone is asking you "why you think you need this?" There's a good chance you don't, and if you refuse to answer the questions of people who are trying to help you, you make it real hard to be helped.

Kacarott ,

Sometimes people want to be generally helped, and sometimes people just want an answer to their question. If the answer is "it's impossible" then that's a valid answer, but if the answer is "I'm not going to tell you, instead I'm going to assume that what you actually want is me to teach you why you were wrong to ask the question in the first place" then theres a good chance that actually they just wanted an answer, and you deciding for them what they need comes across as patronising.

Nibodhika ,

It's not impossible, but each DE has their own context menu, each application has their own context menu, without understanding his use case it's impossible to answer the question. If he had said I want to edit root files then the answer would be the nautilus-admin plugin, but he kept shutting himself and not answering simple question about what is his use case which made it impossible for anyone to answer.

If someone asks how to tie a noose you ask for context, answers are vastly different if he's trying to tie his shoes than if he wants to hang himself. Even if you plan on helping the person hang themselves you need to know the use case. Read some of the replies he sent and you'll see his entire problem is caused by him having run things with sudo to begin with, and now having lots of permissions problems that he thinks the best solution is an easier way to run programs with sudo, which will put him in more of the same situations needing that more and more. He can use his computer however he wants, but at that point it might be easier to just login with the root user and be done with it.

flork OP ,
@flork@lemy.lol avatar

Thank you lol this thread got absurd.

"I won't tell you to open your lunchbox until you tell me what you brought for lunch and the allergies of anyone in your family."

Nibodhika ,

Except the question you're asking is more akin to "How do I fold my lunchbox?" And refused to provide any more meaning to what you want other than "I used to fold my tinfoil, I now have a lunchbox and want to fold it in the same way, it's not difficult".

You're asking something that you shouldn't do, you only need this because you already did it before and broke a lot of the permissions in your system which by your own account caused you headaches. In other words you already folded the lunchbox and when it broke instead of stopping and thinking about what you did wrong you proceeded on asking on the internet what's the proper way to fold your lunchbox.

flork OP ,
@flork@lemy.lol avatar

Amazing. Yes, when I said "open" I actually secretly meant "fold", a totally normal and common mistake users make when accessing the contents of a lunchbox. Everything is an XY problem!

Nibodhika ,

Except you didn't, that's what you're missing, you're asking how to do a Windows thing on Linux, and despite everyone telling you you don't need this you keep insisting on it. Your whole problem started because you ran a program with sudo, and instead of acknowledging your mistake and asking how to fix the original problem and un-clusterfuck your drives you double down and insist the community is being toxic because they refuse to tell you how to easily keep insisting on the error.

Nibodhika ,

It is, run as administrator is a windows concept, in Linux programs that need elevated privileges will ask for it, so if you need a specific program to be entirely elevated you're asking something quite unique. I've asked multiple times, I'll ask again, why do you want this? Give me a concrete example of what you're trying to do, just saying running any program as root is not a good answer.

Since I know you're not going to (because I already asked at least 3 times and others have as well and you haven't answered anyone, so I think you don't know why you want this other than "because Windows has it"), here's the generic answer for you, on the login screen type root as your user and input your root password, there you go, you don't even need that menu item anymore since everything runs as root now, just like in Windows.

2xsaiko ,
@2xsaiko@discuss.tchncs.de avatar

For files, you should use an editor that supports it (e.g. Kate via admin:// paths). You should not run GUI programs as root.

lemmyvore ,

Or sudoedit in console.

HumanPerson ,

I think you are right that people want a solution to a problem they don't have, but I think in this case they may just want to run executable files as sudo from a GUI.

Nibodhika ,

Which program/files and from which GUI? Each GUI will have it's own way of doing that, and on 99% of cases it's not necessary. He consistently refuses to answer simple questions about what he's ultimately trying to accomplish. I have a generic way of doing that, login with the root user. Do you think that's a bad idea? Then list all of the reasons why using root as your main user is a bad idea and probably every single one will apply to what he wants as well. There's a reason why programs that need root access ask for it and don't expect you to run them with sudo, the "run as administrator" is a windows concept from an OS that doesn't have a proper way to elevate privileges so programs can't implement that API and you need to elevate the entire program.

FrostyPolicy ,
@FrostyPolicy@suppo.fi avatar

Sudo is “su do”, i.e. “run as root”

It may default to root but it doesn't mean run as root. Su means substitute user identity i.e. any other user (if you have the rights to it).

Nibodhika ,

I know, but explaining all that for just a comment on why I found funny the "run as sudo" seemed too much.

patatahooligan ,
@patatahooligan@lemmy.world avatar

Both su and sudo originally meant "superuser" because that was their only use. They have retroactively been changed to "switch user" because this functionality was added later.

MonkderDritte ,

Thunar has 'custom actions'. Add one using pkexec %f. Other FM have similiar functionality.

prunerye ,

Thank you for providing an actual answer. Most of the comments in this thread are condescending as hell.

ZWQbpkzl ,

We must first ask What GUI program are you trying to run as root?

flork OP , (edited )
@flork@lemy.lol avatar

gedit, gparted, many others. I am not afraid of the terminal it's just not my preferred method.

priapus ,

gedit uses polkit and should prompt you with a password when modifying a file that needs root priviledges. you shouldn't have to run it as root

flork OP ,
@flork@lemy.lol avatar

Nope, gedit opens fine but you can't save changes unless you're root. This is true of every distro I've tried.

priapus ,

ah I may have mixed its behaviour up with kate

ZWQbpkzl ,

There's programs like kdesu which you can use. Idk if you can (or should) hack a context menu for a run-as-root option on everything. But you can make aliases or specifically application menu items for the specific apps you want to use.

https://superuser.com/questions/135311/sudo-access-for-desktop-actions-in-gnome-kde#135325

  • All
  • Subscribed
  • Moderated
  • Favorites
  • linux@lemmy.ml
  • random
  • All magazines