add user delete user linux debian based

I add or delete users if not every day, at least every other day. Linux systems come with utilities that make it easy. However, I still need to browse their man pages and when on debian based systems I just use the adduser script.

#!/bin/bash
##adduser.sh
###g0 ,2010 , aLog.ipduh.com , kod.ipduh.com

INTERACTIVE=1

GROUPID=""
GROUPNAME=""
USERID=""
USERNAME=""
USERHOMEDIR=""
USERSHELL=""
USERCOMMENT=""

if [ "$INTERACTIVE" -eq 1 ] ; then

echo "Add User:"
read -p "Enter GROUPID     : " GROUPID;
read -p "Enter GROUPNAME   : " GROUPNAME;
read -p "Enter USERID      : " USERID;
read -p "Enter USERNAME    : " USERNAME;

read -p "Enter USER HOME DIRECTORY ( Or hit enter for /home/$USERNAME ): " USERHOMEDIR;
if [ -z "$USERHOMEDIR" ] ; then
        USERHOMEDIR="/home/${USERNAME}"
fi

read -p "Enter USERSHELL   : " USERSHELL;
read -p "Enter USERCOMMENT : " USERCOMMENT;

fi

groupadd -g $GROUPID $GROUPNAME
cp -r /etc/skel /home/$USERNAME
useradd -u $USERID -g $GROUPID -d "/home/$USERNAME" -s "$USERSHELL" -c "$USERCOMMENT" $USERNAME
chown -R $USERNAME.$GROUPNAME /home/$USERNAME
passwd $USERNAME



To add a user:
ares:~/scripts#chmod 700 adduser.sh 
ares:~/scripts#./adduser.sh 
Add User:
Enter GROUPID     : 1234
Enter GROUPNAME   : foo_group
Enter USERID      : 1234
Enter USERNAME    : foo_user
Enter USER HOME DIRECTORY ( Or hit enter for /home/foo_user ): 
Enter USERSHELL   : /bin/bash
Enter USERCOMMENT : da foo   
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully


Let's check
ares:~/scripts#grep foo_user /etc/passwd
foo_user:x:1234:1234:da foo:/home/foo_user:/bin/bash
ares:~/scripts#grep foo_user /etc/shadow
foo_user:$6$gj0o20tJ$jvHSyqNKyITKJEjN.zoMeaAPyzrANaAyM6PbG5ncka6otd2LRZJPK1Uchzu.fyLHXLB9ny5XgpCaV4QwyAo.a0:15471:0:99999:7:::
ares:~/scripts#grep foo_group /etc/group
foo_group:x:1234:



Cool, everything seems OK.

Let's delete foo_user and foo_group
ares:~/scripts#deluser foo_user
Removing user `foo_user' ...
Warning: group `foo_group' has no more members.
Done.
ares:~/scripts#delgroup foo_group
Removing group `foo_group' ...
Done.


Let's check again.
ares:~/scripts#grep foo_user /etc/passwd
ares:~/scripts#grep foo_group /etc/group
ares:~/scripts#



add delete users - linux