Linux script to add user and add into sudo

DevOps

MOTOSHARE 🚗🏍️
Turning Idle Vehicles into Shared Rides & Earnings

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Owners earn. Renters ride.
🚀 Everyone wins.

Start Your Journey with Motoshare
#!/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