Linux script to add user and add into sudo

DevOps

YOUR COSMETIC CARE STARTS HERE

Find the Best Cosmetic Hospitals

Trusted • Curated • Easy

Looking for the right place for a cosmetic procedure? Explore top cosmetic hospitals in one place and choose with confidence.

“Small steps lead to big changes — today is a perfect day to begin.”

Explore Cosmetic Hospitals Compare hospitals, services & options quickly.

✓ Shortlist providers • ✓ Review options • ✓ Take the next step with confidence

#!/bin/bash
# Usage: sudo ./add_sudo_user.sh <username>

set -e

if [ -z "$1" ]; then
    echo "Usage: $0 <username>"
    exit 1
fi

USERNAME="$1"

# Create user with bash shell
sudo adduser --shell /bin/bash "$USERNAME"

# Add user to sudo group
sudo usermod -aG sudo "$USERNAME"

# Setup passwordless sudo
echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/"$USERNAME" > /dev/null
sudo chmod 0440 /etc/sudoers.d/"$USERNAME"

echo "User $USERNAME created and configured for passwordless sudo."Code language: PHP (php)

How to run this script?

vi adduser.sh
chmod 755 adduser.sh
./adduser.sh <<USERNAME>>
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x