jump to navigation

Script To Delete A User January 11, 2009

Posted by ModelR in UBUNTU LAMP Project.
trackback
THIS IS A SUBSECTION OF THE VERY VITAL UBUNTU LAMP SERVER PROJECT

You can find the full outline of this project here:
LINK: Very Vital Ubuntu LAMP Server Project Outline

Please support this project.
Make A Donation

Download a copy of the script to look over: removeuser.sh in text format

Create a new file called “/usr/local/bin/removeuser.sh:
$ sudo nano /usr/local/bin/removeuser.sh

#!/bin/bash
# Script to remove a user to Linux system
echo ""
echo "******************************"
echo "*Delete a user from the system*"
echo "******************************"
echo ""
if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
read -p "Delete $username from the system? Type YES To delete: " confirm
if [ "$confirm" == "YES" ]; then
smbpasswd -x $username
deluser $username
rm -rf /home/$username
echo ""
echo ""
echo "$username successfully removed from the system."
echo ""
else
echo ""
echo "$username was not deleted."
echo ""
exit 1
fi
else
echo ""
echo "$username does not exist"
echo ""
fi
else
echo "Only root can delete a user from the system"
exit 2
fi

Make the script executable
$ sudo chmod 755 /usr/local/bin/removeuser.sh

Advertisements

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: