You are not logged in.

#1 2009-10-09 20:46:38

warnec
Member
From: Poland
Registered: 2009-06-22
Posts: 166

Make sudo work like UAC in Vista? :P

So what annoys me in Linux is the fact that typing a command with sudo requires me to type in the password, and then pressing Enter.  tongue

I don't want to disable it - I know you guys keep saying about the perils it brings (I don't buy that "security" stuff, since there are a few to none viruses on Linux - I am more convinced by the fact that I could execute something like 'sudo rm -rf' by accident.)

What I'd like to do, is to make it work like UAC in Vista (yeah, I know, crazy!) so that I get asked a question like "This command is going to be executed with administrator priviliges, are you sure you want to run it?" And "Y/n" prompt.

Y would result in running (without asking for passoword), and n would obviously result into not-executing wink


What do you think? Is it possible to achieve?

Offline

#2 2009-10-09 20:48:52

warnec
Member
From: Poland
Registered: 2009-06-22
Posts: 166

Re: Make sudo work like UAC in Vista? :P

One thing bugs me, though - many scripts (I think some in AUR, too!) are written in such a way that they echo a sentence prompting the user for a password and then sending the user's input into the process run by the script (If you know what I mean).

Would such scripts still work?

Offline

#3 2009-10-09 20:57:21

quarkup
Member
From: Portugal
Registered: 2008-09-07
Posts: 497
Website

Re: Make sudo work like UAC in Vista? :P

well u can use kdesu or gksu or gksudo or something like that (qt has one password dialog also)..


yes it would be cool. the nearest thing I have here is the "kwallet" which is the password manager.


anyway is insecure:

- if UAC asks you for no password it's because you are an administrator, and if you want a secure system, you should be not the "root" user, this way you need of a password


but hey, i believe u can do it simply..
use visudo to allow a program (which asks for permissions) to use sudo without password.

then just set up the system (aliases/symlinks/settings and everything) to use that program.
btw: the program should be run with "sudo <program>"

this way you don't need the pass because the program has passwordless access to super user permissions.



btw: nice idea. I would use that (but with password)..

if u find a program over the web post it here. so someone get a PKGBUILD or something smile

Last edited by quarkup (2009-10-09 20:59:48)


If people do not believe that mathematics is simple, it is only because they do not realize how complicated life is.
Simplicity is the ultimate sophistication.

Offline

#4 2009-10-09 21:11:46

warnec
Member
From: Poland
Registered: 2009-06-22
Posts: 166

Re: Make sudo work like UAC in Vista? :P

The thing is, it would be best to se it globally wink I don't want to think what command will I use in sudo. It is easy to make every sudo command work w/o pass in /etc/sudoers, but the thing I want is the prompt wink

BTW.: I know it's kinda radical, so I don't know if I'll ever use something like this. I just thought about it today. I've got another post here:

http://forum.kde.org/viewtopic.php?f=22&t=82791

Because the trick we're discussing here would only work in console, and disabling kdesu password prompt would require a different approach, I think.

Last edited by warnec (2009-10-09 21:12:01)

Offline

#5 2009-10-09 21:17:05

Ranguvar
Member
Registered: 2008-08-12
Posts: 2,549

Re: Make sudo work like UAC in Vista? :P

This should be fairly trivial, but would require source code editing.

Seriously though, Microsoft fails here.  If UAC is giving you messages with no password request, as quarkup said, you're running as Admin, which is unsecure for many reasons.  The reason sudo asks you for the password is because on GNU/Linux, you don't run as the equivalent of a Windows admin, root, all the time.  Instead, you use sudo to gain those privileges temporarily, and the reason why is apparent.ks you for the password is because on GNU/Linux, you don't run as the equivalent of a Windows admin, root, all the time.  Instead, you use sudo to gain those privileges temporarily, and the reason why is apparent.  Windows, rather, is letting you run as admin and then warning you when you do potentially dangerous things... suppose someone hacks your user account on Windows, aka your admin account, they then have full control.  On GNU/Linux, they then must get your password to get to root-level access.

The best solution would be to increase the sudo timeout time, and possibly use a wallet system.

Last edited by Ranguvar (2009-10-09 21:17:27)

Offline

#6 2009-10-09 21:38:34

AngryKoala
Member
Registered: 2009-01-22
Posts: 197

Re: Make sudo work like UAC in Vista? :P

Isn't any timelimit on sudo a vulnerability?  Couldn't there just be a script that polls for a sudo usage and then rattle off a bunch of admin privileged commands?  My timeout is 0, which means I have to type my password a lot, but I'm fast at it now =/

Offline

#7 2009-10-09 22:49:15

quarkup
Member
From: Portugal
Registered: 2008-09-07
Posts: 497
Website

Re: Make sudo work like UAC in Vista? :P

well u don't really need to use "sudo <command>" (then a visudo configured user's password, you or another non-root user)


u can use "su -c <command>" (then the root's password)

basically that would be almost the same thing big_smile


If people do not believe that mathematics is simple, it is only because they do not realize how complicated life is.
Simplicity is the ultimate sophistication.

Offline

#8 2009-10-10 06:22:24

xd-0
Member
From: Sweden
Registered: 2007-11-02
Posts: 327
Website

Re: Make sudo work like UAC in Vista? :P

* Edit the sudoers file so you can run all commands without being prompted for password.
* Then make a bash script that uses gmessage to ask if you want to run the action.  no -> abort  yes -> run the command.
* Overide the ordinary sudo command in your .bashrc so it points to the script.  Should be something like this:

sudo() {
        builtin sudo "$@"
}


Since it's a rather stupid thing to do, the rest is up to you.

Offline

#9 2009-10-10 06:34:41

fumbles
Member
Registered: 2006-12-22
Posts: 246

Re: Make sudo work like UAC in Vista? :P

If you have used Vista, why don't you stick with it? I mean it's not that bad. Now before you grab your torches and pitchforks first let me unpack that. Linux aint Windows and Windows is not Linux. There are not designed for the same purpose, trying to make one like the other is just plain silly. If Windows suites your needs better then you should stick to it.

Otherwise:

#run (as root)  visudo 
#uncomment the line below
 %wheel ALL=(ALL) NOPASSWD: ALL

Then in .bashrc (or whatever)

sudo ()
{ 
      zenity --question
      if [ $? -eq 0 ] ; then
            sudo "$@"
     fi
}

Last edited by fumbles (2009-10-10 06:43:16)

Offline

#10 2009-10-10 07:57:20

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

Re: Make sudo work like UAC in Vista? :P

Let me to ask question near the subject here.
Just wondering, how sudo w/o password can protect against viruses (intruders etc.)?
I don't understand, what prevents virus (intruder) from running "sudo <command>" with user's permissions and without password.
Can someone provide me a link or explain it in some words?

Offline

#11 2009-10-10 09:00:13

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,355

Re: Make sudo work like UAC in Vista? :P

eDio wrote:

Let me to ask question near the subject here.
Just wondering, how sudo w/o password can protect against viruses (intruders etc.)?
I don't understand, what prevents virus (intruder) from running "sudo <command>" with user's permissions and without password.
Can someone provide me a link or explain it in some words?

It doesn't. Though a virus/malware/intruder would need to try sudo and see if it works, first. Most intruders would go directly for the root account, really, because it MUST exist, as opposed to sudo which doesn't have to exist on all systems.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#12 2009-10-10 13:01:11

warnec
Member
From: Poland
Registered: 2009-06-22
Posts: 166

Re: Make sudo work like UAC in Vista? :P

As I said, making sudo without a password is not something I approve.

Well, but the idea to get a "Y/n" prompt is something new, so none of the existing malware files would be smart enough to try sudo and then know they have to give the "Y" answer big_smile

The idea here:

fumbles wrote:
#run (as root)  visudo 
#uncomment the line below
 %wheel ALL=(ALL) NOPASSWD: ALL

Then in .bashrc (or whatever)

sudo ()
{ 
      zenity --question
      if [ $? -eq 0 ] ; then
            sudo "$@"
     fi
}

Is nice, but it displays a GUI window. So It's a good idea when I want to make kdesu display dialog window for Yes/No,
but when I launch a program in Konsole I don't want to make it open up a GUI window. I'd prefer the prompt to be echoed in the CLI itself. Can it be done?

BTW.: zenity is GTK, right? Are there any KDE alternatives? I remember there was something like knotify in my opensuse 11.1 days. I can't find any package of that name in pacman, though...

Offline

#13 2009-10-10 13:50:03

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

Re: Make sudo work like UAC in Vista? :P

Other alternative is run gksu (or kdesu) and check the box with 'Remember password'.


(lambda ())

Offline

#14 2009-10-10 15:47:53

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Make sudo work like UAC in Vista? :P

You can always change your root password to Y.

Offline

#15 2009-10-10 17:58:44

warnec
Member
From: Poland
Registered: 2009-06-22
Posts: 166

Re: Make sudo work like UAC in Vista? :P

@up

rofl.

Offline

#16 2009-10-10 18:17:26

ezzetabi
Member
Registered: 2006-08-27
Posts: 947

Re: Make sudo work like UAC in Vista? :P

alias sudo=' zenity --question --text "Are you sure you want to execute this program as root?" && sudo '

Offline

#17 2009-10-10 18:28:27

some-guy94
Member
Registered: 2009-08-15
Posts: 360

Re: Make sudo work like UAC in Vista? :P

warnec wrote:

BTW.: zenity is GTK, right? Are there any KDE alternatives? I remember there was something like knotify in my opensuse 11.1 days. I can't find any package of that name in pacman, though...

There is kdialog (and dialog for cli)

Offline

#18 2009-10-10 22:50:45

warnec
Member
From: Poland
Registered: 2009-06-22
Posts: 166

Re: Make sudo work like UAC in Vista? :P

Right, so assuming I've got it set that way that kdesu uses su and sudo in CLI uses sudo, it would seem like possible to make correct entried in .bashrc to make sudo open the dialog cli prompt, and su kdialog gui prompt, right?

PS.: Dialog opens notifications in CLI, but these are big ugly boxes. I prefer plain text. I'd give a shot to what some other people suggest here and post some examples (scripts)

PPS.: How can I make bashrc differentiate between kdesu and sudo? If I set kdesu to use su, that's easy. But that way it won't follow /etc/sudoers file, so will still ask for password. And making it run sudo would make it impossible for the system to tell if it's a sudo command invoked by GUI or CLI right?

PPPS.: And please remember, if you want to help me, don't post the commands (like the zenity one I just tried) which will open a GUI window when I operate in CLI ok? Thanks!

Last edited by warnec (2009-10-10 23:02:26)

Offline

#19 2009-10-11 19:14:24

loafer
Member
From: the pub
Registered: 2009-04-14
Posts: 1,772

Re: Make sudo work like UAC in Vista? :P

You could also consider using something other than sudo.  I recommend super, which is available in the AUR.  You can configure super to run scripts and applications as root (or another UID/GID) with or without a password.  You can then set your scripts to prompt y/n before executing them.


All men have stood for freedom...
For freedom is the man that will turn the world upside down.
Gerrard Winstanley.

Offline

#20 2009-10-11 20:09:16

warnec
Member
From: Poland
Registered: 2009-06-22
Posts: 166

Re: Make sudo work like UAC in Vista? :P

Seems like something I could use, but I've honestly no idea how could I construct the rule in .bashrc to display y/n prompt for sudo command.... It's a newbie corner after all, I'm not a uber-hax0r yet tongue

PS.: And how to construct a rule to display a GUI box when running kdesu. I can use something like "alias su='kdialog --prompt y/n'" but I don't know how the command kdesu uses works:

[warnec@chakra ~]$ LANG=C su kate
su: user kate does not exist
[warnec@chakra ~]$

Last edited by warnec (2009-10-11 20:09:46)

Offline

#21 2009-10-11 20:23:40

loafer
Member
From: the pub
Registered: 2009-04-14
Posts: 1,772

Re: Make sudo work like UAC in Vista? :P

You said above that you did not want non cli commands and super does not use sudo at all.  I have no idea how kate or any kde apps work.  If you would like to try super install it from aur and send me an email if you get stuck.

Last edited by loafer (2009-10-11 20:29:10)


All men have stood for freedom...
For freedom is the man that will turn the world upside down.
Gerrard Winstanley.

Offline

#22 2009-10-11 21:07:48

warnec
Member
From: Poland
Registered: 2009-06-22
Posts: 166

Re: Make sudo work like UAC in Vista? :P

Maybe I didn't make it clear, or I made a mistake somewhere - what I want, is:

1) Launching 'sudo command' in CLI or Konsole or Yakuake or whatever brings up a small text asking "Are you sure to ivoke this command in administrator mode? [Y/n]"

2) Launching 'kdesu kate' or 'kdesu whatever' brings up a Kdialog GUI window asking "Are you sure to run this program in administrator mode?" And two buttons: Yes/No.

Y results in running in admin mode without asking for password, n results in (1)coming back to the command prompt (2)closing window.

Last edited by warnec (2009-10-11 21:09:25)

Offline

#23 2009-10-12 00:00:29

TheSaint
Member
From: my computer
Registered: 2007-08-19
Posts: 1,523

Re: Make sudo work like UAC in Vista? :P

warnec wrote:

but when I launch a program in Konsole I don't want to make it open up a GUI window.

by dialog would be achievable.

warnec wrote:

I'd prefer the prompt to be echoed in the CLI itself. Can it be done?

In linux nothing is impossible, just to know a bit of bash scripting or higher level programming scripts.

warnec wrote:

BTW.: zenity is GTK, right? Are there any KDE alternatives? I remember there was something like knotify in my opensuse 11.1 days. I can't find any package of that name in pacman, though...

In KDE we have kdialog included hidenly wink . Just to try kdialog --help or look at this page. Also zenity<>kdialog conversion available on demand wink

warnec wrote:

Y results in running in admin mode without asking for password, n results in (1)coming back to the command prompt (2)closing window

The environment variable TERM is the answer. If you try kdialog --msgbox "This is $TERM" either in console or ALT+F2 and input the command there, you'll get the answer wink

F

Last edited by TheSaint (2009-10-12 00:26:23)


do it good first, it will be faster than do it twice the saint wink

Offline

#24 2009-10-12 00:38:51

some-guy94
Member
Registered: 2009-08-15
Posts: 360

Re: Make sudo work like UAC in Vista? :P

warnec wrote:

Maybe I didn't make it clear, or I made a mistake somewhere - what I want, is:

1) Launching 'sudo command' in CLI or Konsole or Yakuake or whatever brings up a small text asking "Are you sure to ivoke this command in administrator mode? [Y/n]"

Add this to ~/.bashrc (or some file in /etc/profile.d)

uac_sudo()
{
local answer
read -p "Are you sure to invoke this command in administrator mode? [Y/n] " answer
case $(echo $answer | tr [:upper:] [:lower:]) in
    n|no)
        return
        ;;
    *)
        /usr/bin/sudo $@
        ;;
esac
}

alias sudo="uac_sudo"
warnec wrote:

2) Launching 'kdesu kate' or 'kdesu whatever' brings up a Kdialog GUI window asking "Are you sure to run this program in administrator mode?" And two buttons: Yes/No.

Y results in running in admin mode without asking for password, n results in (1)coming back to the command prompt (2)closing window.

Do something similar to above using kdialog and give it a different name

Last edited by some-guy94 (2009-10-12 00:39:33)

Offline

#25 2009-10-12 05:43:19

warnec
Member
From: Poland
Registered: 2009-06-22
Posts: 166

Re: Make sudo work like UAC in Vista? :P

@ up

great thanks, but in this case you were able to give the command an alias:

alias sudo="uac_sudo"

And I don't know how the command for kdesu should work. Maybe

alias kdesu="uac_kdesu"

xD?
So something like this?:

uac_kdesu()
{
kdialog --yesno "Are you sure to run this program in administrator mode?"

What's next? You are able to read  an answer from user's console input, and how is kdialog supposed to work to do that? I can't script man tongue Help me, please wink

Offline

Board footer

Powered by FluxBB