LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-19-2019, 10:50 AM   #1
volcblack
Member
 
Registered: Apr 2018
Posts: 36

Rep: Reputation: Disabled
script for sudo users


Hello Community,

I am trying to display, the users that has sudo perms.

I tried some scripts from other sites, tried to grep -i all /etc/sudoers

but I saw greping the /bin/bask from /etc/sudoers would give me the login users.
so if I run sudo -l -U user would give me output if the user has sudo perms.

It's there a way to have the output of grep "/bin/bash" /etc/passwd
and the take that users output to run sudo -l -U

I know that it should be a for or while script but don't know how.
 
Old 01-19-2019, 11:02 AM   #2
individual
Member
 
Registered: Jul 2018
Posts: 282
Blog Entries: 1

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by volcblack View Post
Hello Community,

I am trying to display, the users that has sudo perms.

I tried some scripts from other sites, tried to grep -i all /etc/sudoers

but I saw greping the /bin/bask from /etc/sudoers would give me the login users.
so if I run sudo -l -U user would give me output if the user has sudo perms.

It's there a way to have the output of grep "/bin/bash" /etc/passwd
and the take that users output to run sudo -l -U

I know that it should be a for or while script but don't know how.
There's an easier way than what you're trying to do.
Code:
grep -E 'wheel|sudo' /etc/group
Code:
wheel:x:10:root,user
 
Old 01-19-2019, 11:07 AM   #3
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,856
Blog Entries: 3

Rep: Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409
Quote:
Originally Posted by volcblack View Post
I know that it should be a for or while script but don't know how.
You can use a for loop along with command substitution with AWK to make a list of accounts.

Code:
for u in $(awk '$3>=1000{print $1}' FS=':' /etc/passwd); 
do 
        echo $u;
        sudo sudo -l -U $u; 
        echo;
done
Try it in pieces. Using a colon : as the field separator, print the user name (field #1) when UID (field #3) is 1000 or above:

Code:
awk '$3>=1000{print $1}' FS=':' /etc/passwd
Then put it into a for loop:

Code:
for u in $(awk '$3>=1000{print $1}' FS=':' /etc/passwd); 
do 
        echo $u;
        echo;
done
Finally, add in sudo. It is needed twice so that the second one is run as root.

As for learning more, see
http://www.grymoire.com/Unix/Awk.html
https://mywiki.wooledge.org/BashGuide

as two examples of guides.

However, keep checking the reference manuals:

Code:
man awk
man bash
They'll make sense over time as you learn to navigate them. However, don't worry that the second one is overwhelming, the manual page is searchable.
 
1 members found this post helpful.
Old 01-23-2019, 10:05 AM   #4
volcblack
Member
 
Registered: Apr 2018
Posts: 36

Original Poster
Rep: Reputation: Disabled
Thanks

It works perfectly, thank you so much
 
  


Reply


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
LXer: The Ultimate Sudo FAQ To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
[SOLVED] Need sudo for users but only +r on other /home/users Ubuntu 10.04 sundry_50 Linux - Security 3 11-07-2010 07:22 PM
Script needed to get users with sudo access mikeb75 Linux - Server 1 12-01-2009 12:21 PM
Restricting Editing in Sudo (Advanced Sudo Question) LinuxGeek Linux - Software 4 11-04-2006 03:20 PM
Sudo without having to type "sudo?" Mitch G Linux - Security 3 09-28-2006 02:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:10 AM.

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