Question: Hello there. I'd been trying to run the following script, but failed. Please help me with this part. I am not sure what is wrong.

Hello there. I'd been trying to run the following script, but failed. Please help me with this part. I am not sure what is wrong. I am working on Linux Ubuntu 18.04.

Please provide the screenshot and explanation. I promise to give you thumb up.

The request:

Create a script so that the user (in this case an admin or root) can input a defined username and grant the newly created user an encrypted password.

The final script should be:

Enter username:

Enter password:

User has been added to the system!

My Script on Nano

if [ $(id -u) -eq 0 ]; then

read -p "Enter username : "

read -s -p "Enter password : "

egrep "^$username" /etc/passwd >/dev/null

if [ $? -eq 0 ]; then

echo "$username exists!"

exit 1

else

pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)

useradd -m -p "$pass" "$username"

[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"

fi

else

echo "Only root may add a user to the system."

exit 2

fi

When I ran the script on my linux terminal:

sudo cmod a+x useradding.sh

./useradding.sh

But the response is the following :

Only root may add a user to the system

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!