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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started