Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-01-2008, 04:28 AM   #1
Registered: Nov 2002
Posts: 207

Rep: Reputation: 32
super user privileges check for a normal user in bash script


I want to check if a normal user has super user privileges. For example, I run a script as user bond:

bond $ ./
in my I want to find out if bond has super user privileges, i.e he/she can run sudo command.

Is it possible? Consider I can't read /etc/sudoers file. I don't wan't to ask for password and then fail. I just want to say:
"You don't have sudo privileges... aborting"

Old 08-01-2008, 05:03 AM   #2
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417

Rep: Reputation: 33
No you cannot do this. The problem is that anyone CAN run the sudo command, but until authentication it is not known what privileges they have. What you can do is grab the password and run a `CMD_LIST=$(echo $PASSWD | sudo -L -S)` and process the output and/or exit code to determine if they have necessary rights.
Old 08-01-2008, 06:08 AM   #3
Registered: Nov 2002
Posts: 207

Original Poster
Rep: Reputation: 32

that's a bummer, but not much one can do. Thanks jcookeman



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Root user check in bash script doesn't work tawalker Programming 6 12-18-2011 03:06 AM
Create a normal “user” with “shut down” privileges? John79 Linux - Newbie 2 02-18-2008 03:43 AM
Linux - How to add a new user with the same root/super-user's privileges? asgarcymed Linux - General 8 12-23-2006 07:45 PM
Running super user commands as normal user mickyg Linux - Security 5 10-14-2005 07:25 PM
normal user = super user jayakrishnan Linux - General 4 03-19-2002 09:58 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:43 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration