Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically invoking gksudo like UAC

Tags:

linux

sudo

uac

This is about me being stressed by playing the game "type a command and remember to prepend sudo or your fingers will get slapped".

I am wondering if it is possible somehow to configure my Linux system or shell such that when I forget to type e.g. "sudo apt-get install emacs", instead of just telling me that I did something wrong, gksudo would get launched, allowing me to acknowledge my credentials and get on moving. 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: Thanks everyone for your interrest. Unfortunately, Daenyth and bmargulies answers and explanations are what I anticipated/feared since it was impossible for me to google-up a solution prior to submitting this question. I hope that some nice person will someday provide an effective solution for this.

BR, Christian

like image 537
Christian Madsen Avatar asked Jul 06 '10 15:07

Christian Madsen


2 Answers

Linux doesn't allow for this. Unlike Windows, where any program can launch a dialog box, and UAC is in the kernel, Linux programs aren't necessarily GUI-capable, and sudo is not, in this sense, in the kernel. A program cannot make a call to elevate privilege (unless it was launched with privilege to begin with and intentionally setuid'd down). sudo is a separate executable with setuid privilege, which checks for permission. If it likes what it sees, it forks the shell to execute the command line. This can't be turned inside out.

As suggested in other posts, you may be able to come up with some 'shell game' to arrange to run sudo for you for some enumerated list of commands, but that's all you are going to get.

like image 108
bmargulies Avatar answered Nov 05 '22 22:11

bmargulies


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

like image 21
Karl Bielefeldt Avatar answered Nov 05 '22 21:11

Karl Bielefeldt