friendica.vrije-mens.org

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.

Deze entry werd bewerkt (3 weeks ago)
105 18 1
It depends on the file browser you are using.
7 2 1

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.

3 5 1
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?
14 2 1
Not regularly, but the most common use I've encountered is text files used in various configurations.
3 2 1
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.
6 1
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.
1 1

That is the 1% I mentioned, and the easiest way is installing this https://github.com/nautilus-extensions/nautilus-admin which I think is in the apt repos, so probably sudo apt install nautilus-admin works.

But I STRONGLY encourage you NOT to install this, you've already made a mess of permissions on your computer that by your own account caused you many headaches by running graphical programs with sudo without any need.

1 1
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.
1 1
[This comment has been deleted by an automated system]
Deze entry werd bewerkt (2 weeks ago)
9
ctrl+L, there’s no button because Gnome is weird


Oh my gosh, this is so useful. The lack of an address bar was driving me insane. Thanks.

4 1
You have no idea what that would do in Linux. First read some documentation, then decide if you really need it. I guess you can see by the number of people trying to put you on the right path that what you want is not a good idea.
2 4 1
I'm not a child with a machine gun, I just don't want to go to the terminal every time.
3 3 1

Then let us address the underlying issue. You should not need root for the majority of tasks and never for desktop usage.

It sounds like something got messed up when you ran a different program as root.

Deze entry werd bewerkt (3 weeks ago)
2 1 1

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.

3 1
You don't need to run any GUI programs as root.
28 16 1
There's one in every thread.
14 11 1
I have no idea what you are talking about. The answer to your question is: this is impossible and this is done for purpose. Don't try to work in linux like in windows.
13 11 1
I have no idea what you are talking about.


Your attitude.

9 9 1

It's not attitude they are giving you. It's strong recommendation. It's the strong recommendation of the entire Linux community.

Sudo is different than run as admin and is not intended to be used to do things the way Windows does them.

6 3 1
Now this is actually wrong. Firewall gui for example requires root. There are similar sysadmin guis that need it too
16 2 1
Sysadmin GUI tools are designed to be secure by isolating GUI from privileged process. That is not true for a random GUI app.
8 1 1
No. It's ”you probably shouldn't run them with sudo” , many GUIs need root for certain tasks. I recommend using pkexec instead of sudo, you can add it to the .desktop file and when you launch the application it'll give you a GUI authentication prompt.
12 1
Probably? They won't run with sudo normally (in xorg at least). And only those explicitly allowed to be run with pkexec by maintainers will do. Of course it is possible to evade this restriction, but you definitely should not.
3 1
There's plenty of GUI applications that'll run just fine with sudo. For example BleachBit. \
Sudo is just not made for use with GUI and can possibly lead to bad behavior. pkexec leverages PAM & Polkit and is intended for GUIs.
Deze entry werd bewerkt (3 weeks ago)
3 1
It's not when app was written. Wayland apps probably work with sudo, x11 don't because sudo does not pass the $DISPLAYenvironment variable. It's a correct behavior of sudo because running x11 apps with root permission you create a security hole.
2 1
I know. Don't do this. Read the manual.
1
Polkit was created in 2001 & PAM was created in 1995. GNU dates back to 1984, so... There's still quite a handful of programs that are likely still maintained to this day that don't properly take advantage of them or other auth systems made to be able to handle GUIs in a secure fashion. BleachBit being released in 2008.
Deze entry werd bewerkt (3 weeks ago)
1
Idk what is bleachbit. But I know that "auth systems" can't "handle GUIs in a secure fashion". The app itself can be secure or not. By default they are not secure if they provide a GUI running in privileged process.
1

gksu, kdesu, sux, & polkit. All of which are privilege elevation frameworks that can securely obtain the required privileges without running GUI applications directly as root. Granted you may need to configure PAM & Polkit's policies to make them more secure. \
The problem with sudo is that it runs the entire GUI application as Root; at least by default behavior. These frameworks are the proper way.

BleachBit is a cross-platform disk space cleaner that was based on Python, PyGTK, & GTK2 and then later ported to Python 3 & GTK3. BleachBit on Linux never prompts the user for authentication for operations requiring elevated privileges, it just fails with "permission denied". Inturn you can use sudo, or the by far more recommended and safer option gksudo/gksu & pkexec. In this case, a user can 100% make the mistake of using sudo, and while it's not inherently problematic for this specific case, as we've already discussed it's still risky.

Deze entry werd bewerkt (2 weeks ago)
2 3 1

gksu and kdesu are unsupported for >10 years iirc, they were not more secure than sudo and that's one of the reasons they were abandoned. I've never heard about sux. Polkit is a bit another thing that indeed replaced them, however it does not and can not separate GUI and non-GUI processes. The process itself has to fork, drop privileges and draw a GUI after that. There's no difference between running it via sudo or pkexec, however polkit provide additional protections to prevent running unsafe apps with elevated privileges.

PAM and GVFS are not "privilege elevation frameworks" whatever you mean by this.

1 1 1
Deze entry werd bewerkt (2 weeks ago)
1
[This comment has been deleted by an automated system]
Deze entry werd bewerkt (2 weeks ago)
Nope. Running GUI as root in the same X server as unprivileged apps is insecure because each of them can take control over privileged window. IDK if this issue has been addressed in Wayland, but anyway there are no wayland-only distros nowadays.
[This comment has been deleted by an automated system]
Deze entry werd bewerkt (2 weeks ago)
Now i question why the whole GUI needs to run as root (even in working default config) instead of just the tool running the command with root.
[This comment has been deleted by an automated system]
Deze entry werd bewerkt (2 weeks ago)
Also, most programs are more than wrappers around command line tools


But not gparted.

[This comment has been deleted by an automated system]
Deze entry werd bewerkt (2 weeks ago)

AFAIK the newer Ubuntu gksu equivalent is pkexec, if that helps.

You could cooy all system .desktop files to your home dir and automatically edit them with a script that adds an action to run them with pkexec or sudo as root. However, most GUI apps shpuld never be run as root, because they can break the system. For example, they may create hidden thumbnail files owned by root and break thumbnails in all apps not running as root that way

Deze entry werd bewerkt (3 weeks ago)
22 1
Thanks, I'll give it a shot. I don't want it to always run everything as root, just on rare occasions.
3 2 1
Can confirm the caution here. Bricked a system this way a while back.
12 1

something like this? creating custom context menu options

https://www.howtogeek.com/116807/how-to-easily-add-custom-right-click-options-to-ubuntus-file-manager/

2 1 1
Your polkit will always prompt you for a password. No need to complicate it. If it doesn't, then it doesn't need to be ran as root
21 1 1
Obviously I would want to input a password.
Deze entry werd bewerkt (1 week ago)
6 4
Polkit (Policy Kit) is an authorization framework used in modern Linux distributions to manage access rights and privileges on the system. It allows unprivileged processes to communicate with privileged processes in a controlled and secure manner. \
pkexec a command used to execute commands with elevated privileges, leverages both PAM (Pluggable Authentication Modules) and Polkit to authenticate the user and authorize the requested action.
PAM is a framework used in Linux systems to handle user authentication and authorization. \
Check out Polkit & PAM
Deze entry werd bewerkt (3 weeks ago)
12 1
Deze entry werd bewerkt (3 weeks ago)
9 1 1
We must first ask What GUI program are you trying to run as root?
5 1
gedit, gparted, many others. I am not afraid of the terminal it's just not my preferred method.
Deze entry werd bewerkt (3 weeks ago)
1 1 1
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
5 1
Nope, gedit opens fine but you can't save changes unless you're root. This is true of every distro I've tried.
3 1 1
ah I may have mixed its behaviour up with kate
1

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

1 1
Thunar has custom actions. Add one using pkexec %f. Other FM have similiar functionality.
Deze entry werd bewerkt (3 weeks ago)
8 2 1
Thank you for providing an actual answer. Most of the comments in this thread are condescending as hell.
5 5 1

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?

22 12 1
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.
3 1 1
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.
4 1
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).

13 1
I know, but explaining all that for just a comment on why I found funny the "run as sudo" seemed too much.
3 3 1
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.
8 1
There is no reason to assume this is an XY problem scenario.

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.

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.
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.
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?"
Deze entry werd bewerkt (3 weeks ago)

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.

1

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.

Deze entry werd bewerkt (3 weeks ago)
1

I think you can run like this:

$ pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY <yourapp>

For example, if I wanna open kgx (a.k.a. Gnome Console), I would run:

pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY kgx

1 3
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.
Deze entry werd bewerkt (3 weeks ago)
65 7 1
It would occasionally be handy running gparted, but for as often as I need to do that sudo gparted works just fine
7 1 1
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.
21 1
I'm not on Gnome, variably either Xfce or LxQt, is probably what's making the difference there
Deze entry werd bewerkt (3 weeks ago)
2 1
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.
18 1
Gparted prompts you to enter your password so it can elevate itself to root.
6 1

What's the use case? What are you running into that you want to launch as sudo through the gui that isn't pulling up the dialogue automatically?

A few folks have argued this is unnecessary, but I'm curious about your perspective on why and when you think it would be useful

10 3 1
What are you running into that you want to launch as sudo through the gui that isn’t pulling up the dialogue automatically?


Almost anything. The first thing I tried to do was delete a file off of a network share. Also, editing the name of a file copied from a network share. Also, editing text files. It has been a frequent headache. I am not afraid of the command line, I just don't prefer it every time.

Deze entry werd bewerkt (3 weeks ago)
That's a permissions problem not a run as root problem.

That was also my take. If it's something you should be able to edit, your user should have permissions to do that. Jumping to running as root every time has lots of unintended consequences.

I do think a functionally similar idea would be a button to "take ownership" (grant r/w/d) of a file that would prompt for root password. That way things don't run as root that shouldn't. Would that be a good compromise between Linux permissions and Windows workflow?

Regarding formatting a drive, whatever program you are doing that in should ask for root p/w when performing that operation. If it just refuses because of permissions that seems like a bug.

Deze entry werd bewerkt (3 weeks ago)
The permissions problem was likely created by running something as root. You have a chicken and the egg problem my friend.
Deze entry werd bewerkt (3 weeks ago)
1

Just saw your edit. One thing you should be doing is taking ownership of directories you plan to be working in. So for an external drive for example, you'd want to make sure your user(s) have r/w/x permission recursively (granting permission for all files and folders underneath using the same command) on the root folder of the drive then you can move stuff on and off freely.

I agree it could be more straightforward, but ideally you'd only have to do it one time when you first use the drive with that machine

Deze entry werd bewerkt (3 weeks ago)
1

Emacs can let you edit root files using TRAMP

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

Deze entry werd bewerkt (3 weeks ago)
1 3 1

What Desktop Environment?

This is very easy in KDE.

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.
[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.

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.

Deze entry werd bewerkt (3 weeks ago)
3 2 1

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.

1 2 1
Not sure if all apps, maybe some work, maybe they use XWayland. Dont do this.
1 1
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.
13 4 1
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.
7 7 1

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.

Deze entry werd bewerkt (3 weeks ago)
4 5 1
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.
2 4 1

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.

1 1
12 1 1

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.

7 1 1
3 1 1

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

8 1

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.

Deze entry werd bewerkt (3 weeks ago)
23 1
Manipulating large amounts of different files in terminal is a pain in the ass and everyone who disagrees is wrong.
5 4 1

Other threads:

You are free to do anything and everything with Linux!


ITT:

YOU CAN'T DO THAT
2 1 1
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.
Deze entry werd bewerkt (3 weeks ago)
1

Deze website gebruikt cookies. Door het gebruik van deze website ga je akkoord met het gebruik van deze cookies.