Question

In Linux SSH Test_ Temporary User Permission Bash Program

In Linux SSH

Test_ Temporary User Permission Bash Program

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:

OUTPUT SCREENSHOT:

COPY CODE:

Test_Temporary.sh:

# Script to add a user to Linux system
if [ $(id -u) -eq 0 ]; then
read -p "Enter UserName : " user #enter the name of the user to be added
read -s -p "Enter Password : " password #enter the password for the provided username
egrep "^$user" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$user exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
sudo useradd -m -p $pass $user
[ $? -eq 0 ] && echo "User has been added to system!.." || echo "Failed to add a user!...."
fi
else
echo "Only Root Can add a user to the system" #shows error
exit 2
fi

Add a comment
Know the answer?
Add Answer to:
In Linux SSH Test_ Temporary User Permission Bash Program
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT