Automatically call gksudo as UAC

It's about being annoyed when playing the game "enter a command and don't forget to add sudo, or your fingers will be punched."

I am wondering if it is possible to somehow configure my Linux system or shell in such a way that when I forget to type, for example. "sudo apt-get install emacs" instead of just telling me that I did something wrong, gksudo will be launched, which will allow me to confirm my credentials and move on. Just like UAC does on windows.

Googling hasn't helped me yet.

So is this possible? Did I miss something? Or am I asking for a square circle?

Edit 2010 July 25th: Thank you all for your interrest. Unfortunately, the answers of Daenyth and bmargulies and the explanations are what I expected / feared, since it was impossible for me to solve the problem before submitting this question. I hope some good person ever becomes an effective solution to this.

BR, Christian

+6
linux uac sudo
source share
6 answers

There is no way to do this given the current linux software stack. In addition, MS has a patent for this behavior - present a user interface identifying an account having a right to permit a task in response to the task being prohibited based on a user current account not having that right.

0
source share

Linux does not allow this. Unlike Windows, where any program can launch a dialog box and UAC is located in the kernel, Linux programs are not necessarily compatible with the graphical interface, and in this sense, sudo is not. A program cannot make a call to elevate privileges (unless it was run with the privilege to start and intentionally setuid'd). sudo is a separate executable file with setuid privilege that checks permission. If he likes what he sees, he expands the shell to execute the command line. It cannot be turned inside out.

As suggested in other posts, you can come up with some kind of β€œshell game” to arrange for sudo to run for a certain list of commands, but that's all you are going to get.

+3
source share

You can do what you want with the preexec hook function, similar to a package not found by the command.

+1
source share

I do not think that this really works in a general way (automatically determining which application needs administrator rights). However, you can create such aliases for each application:

 alias alias apt-get='gksudo apt-get' 

If you type apt-get install firefox , gnome asks for the administrator password. You can store commands in ~./bashrc

0
source share

You can use the shell script as follows:

 #!/bin/bash $@ if [ $? -ne 0 ]; then sudo $@ # or "gksudo $@ " fi 

This will lead to the execution of the command specified in the arguments prefixed with sudo if the command returned with a non-zero return code (i.e. if it failed). Use it, for example, in "SCRIPT_NAME apt-get install emacs". You can save it somewhere in your $ PATH and set it as an alias like this (if you saved it as do_sudo):

 alias apt-get='do_sudo apt-get' 

Edit:. This does not work for programs like synaptic , which work for non-root users, but will have less privileges. However, if the application crashes when called without root privileges (e.g. apt-get ), this works fine.

0
source share

In the case when you want to always run the command with root privileges, but may already be root, you can solve this problem by wrapping a little bash script around it:

 #!/bin/bash if [ $EUID = 0 ]; then " $@ " else gksudo " $@ " fi 

If you call it something like alwaysroot.bash and put it in the right place on your PATH, you can call your other program like this:

 alwaysroot.bash otherprogram -arguments... 

It even correctly processes arguments with spaces.

0
source share

All Articles