LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 04-19-2021, 09:24 AM   #1
imtiaza
LQ Newbie
 
Registered: Nov 2019
Posts: 2

Rep: Reputation: Disabled
How to give Users SUDO Permission from Bash Script


Dear Gurus,

I have found a link (Bash Script) through which we can create Users in Linux. Problem is all the Users created from this script does not have SUDO Permission (root Permissions). Please help, Which and Where I can add the switches/option so that when i execute below Script it create ALL USERS with SUDO permission.

Code:
#!/bin/bash
# NOTE: Be sure to run this script with sudo.

# Read user and password
while read iuser ipasswd; do

# Just print this for debugging.
printf "\tCreating user: %s with password: %s\n" $iuser $ipasswd

# Create the user with adduser (you can add whichever option you like).
useradd -m -s /bin/false $iuser

# Assign the password to the user.
# Password is passed via stdin, *twice* (for confirmation).
passwd $iuser <<< "$ipasswd"$'\n'"$ipasswd"
done < <(paste users.txt passwords.txt)

I just want to know that if i run the above mentioned script it create the users and password from the files (user.txt and passowrd.txt) but did not gave them SUDO permission. I want the script to give users SUDO permission.

Thanks
Malik Adeel Imtiaz
 
Old 04-19-2021, 10:00 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Write a line like this to /etc/sudoers.d/$iuser:
Code:
$iuser   ALL=(ALL:ALL) NOPASSWD: ALL
 
Old 04-19-2021, 10:49 AM   #3
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,579

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Or even better, add a line to give a particular GROUP such permission and make sure your script adds them to that group.

There are clues in the sudoers file you are editing when you use visudo. The man page might also be useful.
 
Old 04-19-2021, 11:18 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,669

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
I am not sure what the point is of creating users that can not login but need sudo or root privileges.
 
4 members found this post helpful.
Old 04-19-2021, 11:28 AM   #5
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
I concur with michaelk, if this is a real word task then it definitely has wrong approach.
 
Old 04-19-2021, 02:34 PM   #6
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,579

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Good catch. These user cannot log in (shell is set to false) and sudo will only work from a logged in user session.

Perhaps you have not fully explained what you need, or have mis-stated the case. Please expand and explain so that we can understand what you are really trying to do.
 
Old 04-19-2021, 11:37 PM   #7
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,620
Blog Entries: 40

Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
I am not sure what the point is of creating users that can not login but need sudo or root privileges.
I am not sure I even want to know... If the case is explained in detail, the context and the motivation of the “project” on a larger scale should be presented.
 
  


Reply

Tags
bash, linux, script, shell, terminal


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
16.04 - Permission denied though I'm sudo and have permission to file insomniacno1 Ubuntu 5 10-22-2020 03:30 AM
[SOLVED] How many LQ users do you have to give "Rep" to, before you can give the same LQ users more "Rep"? jsbjsb001 LQ Suggestions & Feedback 3 04-17-2017 04:38 PM
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
Give www-data permission to sudo dangibas Programming 5 08-30-2010 01:35 PM
How do I give users read but not delete permission suse7.1user Linux - General 2 09-03-2003 05:13 PM

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

All times are GMT -5. The time now is 11:58 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
Open Source Consulting | Domain Registration