How to give Users SUDO Permission from Bash Script

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
imtiaza
Level 1
Level 1
Posts: 1
Joined: Mon Apr 19, 2021 10:24 am

How to give Users SUDO Permission from Bash Script

Post by imtiaza »

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: Select all

#!/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
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: How to give Users SUDO Permission from Bash Script

Post by rene »

Adding -G sudo to the useradd command will work. On Ubuntu/Mint members of UNIX-group sudo are allowed to use the command sudo.
Locked

Return to “Scripts & Bash”