Government Security
Network Security Resources

Jump to content

Photo

Interactive Add User [bash]

- - - - - server shell
  • Please log in to reply
3 replies to this topic

#1 UmInAsHoE

UmInAsHoE

    Private First Class

  • Members
  • 28 posts

Posted 23 March 2006 - 10:25 AM

This is a script i wrote for my mates shell server, it does the following:

-Checks for certain binarys that are installed
-Creates a random password
-Interactivly lets you setup the users email | home | shell | name | nick
-Emails the user there username, password and domain (depending)
-Adds them to a list held in /root/userlist

The program was based off the adduser script found at osix.net, i modified it and my friend bob added the binary checking script to it.

This is a good bash script to learn some things off and to also modify for personal use. This is not an optomised script though ;) things can be done better.

Enjoy ^_^

#!/bin/bash
#Add User, Password Generator, Emailer and List maker script :D
# by typedeaF;; Edited by UmInAsHoE

#Check we can run the script first.
function check() {
WHEREIS="";
CHMOD="";
RM="";
MAIL="";
GROUPADD="";
USERADD="";
AWK="";
echo ""
echo "Searching for dependancies:"
sleep 3
		xi=`whereis whereis`;
		if [ "x$xi" = "x" ]; then
				echo " [!] Whereis was unable to find itself";
				exit 1;
		else
				xm=0;
				for xl in $xi; do
						xm=`expr $xm + 1`;
						if [ "x$xm" = "x2" ]; then
								WHEREIS="$xl";
						fi
				done

				if [ ! -x $WHEREIS ]; then
						echo " [!] Whereis can be executed but not found?";
						exit 1;
				fi;
		fi;

AWK=`$WHEREIS awk `;
		xj=0;
		for xk in $AWK; do
				xj=`expr $xj + 1`;
				if [ "x$xj" = "x2" ]; then
						AWK="$xk";
				fi
		done;

		if [ ! -x $AWK ]; then
				echo " [!] Awk could not be located. Broken System?";
				exit 1;
		fi


USERADD=`$WHEREIS useradd | $AWK '{print $2}' - `;
		if [ "x$USERADD" = "x" ]; then
				echo " [!] Unable to find useradd. Broken Environment?";
				exit 1;
		fi

GROUPADD=`$WHEREIS groupadd | $AWK '{print $2}' - `;
		if [ "x$GROUPADD" = "x" ]; then
				echo " [!] Unable to find groupadd. Broken Environment?";
				exit 1;
		fi

MAIL=`$WHEREIS mail | $AWK '{print $2}' - `;
		if [ "x$MAIL" = "x" ]; then
				echo " [!] Unable to find mail. Broken Environment?";
				exit 1;
		fi

RM=`$WHEREIS rm | $AWK '{print $2}' - `;
		if [ "x$RM" = "x" ]; then
				echo " [!] Unable to find Rm. Broken Environment?";
				exit 1;
		fi

CHMOD=`$WHEREIS chmod | $AWK '{print $2}' - `;
		if [ "x$CHMOD" = "x" ]; then
				echo " [!] Unable to find chmod. Broken Environment?";
				exit 1;
		fi
}



# Make a semi-random password using an array of user-friendly characters
function mkpass() {
  PASS=""
  PASSLEN=8
  array1=( q w e r t y u i o p a s d f g h j k l z x c v b n m
	Q W E R T Y U I O P A S D F G H J K L Z X C V B N M
	1 2 3 4 5 6 7 8 9 0 \! \@ \# \$ \% \^ \& \*
  )
  MODNUM=${#array1[*]}

  count=0
  while [ ${count:=0} -lt $PASSLEN ]
  do
	number=$(($RANDOM%$MODNUM))
	PASS="$PASS""${array1[$number]}"
	((count++))
  done

  echo $PASS
}

# center the text on the screen by finding the horizontal center with max_lines
# max_lines divided by two becomes the center line(aka. line_num)
# use the max lenght of the line divided in half to find the center column
# subtract half the output string from the center to create the offset to indent
function center_txt() {
  PROMPT="$1"
  str_len=${#PROMPT}
  indent=$(( ((max_cols / 2)) - ((str_len / 2)) ))
  line_num=$(( max_lines / 2 ))
  tput cup ${line_num} ${indent}
  echo "$PROMPT"
}

# indent_txt is intended to be used AFTER center_txt
# indent_txt just prints on the current line and centers the text horizontally
# line_num is global, so main keeps track of incrementing it
function indent_txt() {
  PROMPT="$1"
  str_len=${#PROMPT}
  indent=$(( ((max_cols / 2)) - ((str_len / 2)) ))
  tput cup ${line_num} ${indent}
  echo "$PROMPT"
}

# mk_prompt creates an input prompt for the the read function
# 'read -p "==> " variable' would work, but I like this better
function mk_prompt() {
  ((line_num+=2))
  tput cup $line_num 15
  PROMPT="==> "
  echo -n "${blink}${PROMPT}"
  echo -n ${offblink}
}

# This function gathers all the information needed to generate the useradd string
function mkuser() {
  USERNAME=""
  FULLNAME=""
  OTHER=""
  GROUP=""
  HOME=""
  SHELL=""
  ADDY=""

  echo ${term_clr}
  PROMPT="Enter new users E-mail Address"
  center_txt "$PROMPT"
  ((line_num++))
  PROMPT="(ex. test@test.com or 0 for none)"
  indent_txt "$PROMPT"
  mk_prompt
  read ADDY

  echo ${term_clr}
  PROMPT="Enter the new Login account user name"
  center_txt "$PROMPT"
  ((line_num++))
  PROMPT="(ex. xxxxN00b)"
  indent_txt "$PROMPT"
  mk_prompt
  read USERNAME

  echo ${term_clr}
  PROMPT="Enter the users Full Name"
  center_txt "$PROMPT"
  ((line_num++))
  PROMPT="(ex. John Doe)"
  indent_txt "$PROMPT"
  mk_prompt
  read FULLNAME

  echo ${term_clr}
  PROMPT="Select the users Shell"
  center_txt "$PROMPT"
  ((line_num++))
  PROMPT="(ex. type \"1\" for Bash)"
  indent_txt "$PROMPT"
  ((line_num+=2))
  indent=$(( ((max_cols / 2)) - 6 ))
  tput cup $line_num $indent; ((line_num++)); echo "1) Bash"
  tput cup $line_num $indent; ((line_num++)); echo "2) Other"
  mk_prompt
  read REPLY

case "$REPLY" in
  1)
	SHELL="$BASH"
 ;;
  2)
	echo ${term_clr}
	PROMPT="Enter a Shell Location for $USERNMAE"
	center_txt "$PROMPT"
	((line_num++))
	PROMPT="(ex. $BASH)"
	indent_txt "$PROMPT"
	mk_prompt
	read SHELL
 ;;
  * )
	echo "Invalid choice"
 ;;
esac

  echo ${term_clr}
  PROMPT="Select the users Primary Group"
  center_txt "$PROMPT"
  ((line_num++))
  PROMPT="(ex. type \"1\" for Their Username)"
  indent_txt "$PROMPT"
  ((line_num+=2))
  indent=$(( ((max_cols / 2)) - 6 ))
  tput cup $line_num $indent; ((line_num++)); echo "1) Thier Username"
  tput cup $line_num $indent; ((line_num++)); echo "2) Other"
  mk_prompt
  read REPLY

  case "$REPLY" in
  1)
	GROUP="$USERNAME"
	HOME="/home/$USERNAME"
 ;;
  2)
	echo ${term_clr}
	PROMPT="Enter a Group Name for $USERNMAE"
	center_txt "$PROMPT"
	((line_num++))
	PROMPT="(ex. Wheel)"
	indent_txt "$PROMPT"
	mk_prompt
	read OTHER
	GROUP="$OTHER"
	HOME="/home/$USERNAME"
 ;;
  * )
	echo "Invalid choice"
 ;;
  esac
}
# Just reset the terminal to normal
function _quit() {
  reset -Q
  echo "Exiting Add User Script. Bye"
  exit 0
}



# =================================================#
# Begin Main #
# =================================================#

#lets check we can execute script
check

ROOT_UID=0

if [ "$UID" -eq "$ROOT_UID" ]; then


# These are the tput commands used to terminal output formatting
term_clr=$(tput clear)
max_lines=$(tput lines)
max_cols=$(tput cols)
blink=$(tput blink)
offblink=$(tput sgr0)

let CONTINUE=0

# Set up a trap to handle control signals. If you start using temp files then
# this is where you would want to clean up.
trap _quit INT TERM QUIT

ADD=0
while [ $CONTINUE -eq 0 ]
do
  if [ "$ADD" = 0 ]; then
  mkuser
  mkpass
  echo ${term_clr}
groups | grep -iw $GROUP

  if [ `echo $?` = "0" ]; then
	echo ${term_clr}
	PROMPT="User with the following criteria"
	center_txt "$PROMPT"
	((line_num+=2))
	PROMPT="groupadd $GROUP"
	indent_txt "$PROMPT"
	((line_num+=2))
	PROMPT="useradd -d $HOME -p $PASS -g $GROUP -s $SHELL $USERNAME"
	indent_txt "$PROMPT"
	((line_num+=2))

	uline=$(tput smul)
	offuline=$(tput rmul)
	PROMPT="Password: $PASS"
	ADD=1
	str_len=$(( ${#PROMPT} + 8 ))
	indent=$(( ((max_cols / 2)) - ((str_len / 2)) ))
	tput cup ${line_num} ${indent}
	echo -n "${uline}$PROMPT${offuline} "
	tput cup $max_lines

	PROMPT="Press Return to continue and Add User. Press ^C (ctrl + c) to EXIT."
	echo -n "${blink}${PROMPT}"
	echo -n ${offblink}
	read -s

 else
	echo ${term_clr}
	PROMPT="User and Group with the following criteria"
	center_txt "$PROMPT"
	((line_num+=2))
	PROMPT="groupadd $GROUP"
	indent_txt "$PROMPT"
	((line_num+=2))
	PROMPT="useradd -d $HOME -p $PASS -g $GROUP -s $SHELL $USERNAME"
	indent_txt "$PROMPT"
	((line_num+=2))

	uline=$(tput smul)
	offuline=$(tput rmul)
	PROMPT="Password: $PASS"
	ADD=1
	str_len=$(( ${#PROMPT} + 8 ))
	indent=$(( ((max_cols / 2)) - ((str_len / 2)) ))
	tput cup ${line_num} ${indent}
	echo -n "${uline}$PROMPT${offuline} "
	tput cup $max_lines

	PROMPT="Press Return to continue and Add User and Add Group. Press ^C (ctrl + c) to EXIT."
	echo -n "${blink}${PROMPT}"
	echo -n ${offblink}
	ADD=1
	read -s

   fi

   elif [ "$ADD" = 1 ]; then
		  #Add the group
		  groupadd $GROUP
	  if [ "$ADDY" = "0" ]; then

		 # Create the user and add the user to the list with no email
 
		 ADDUSER="################################\n Username = $USERNAME\n Password = $PASS\n FullName = $FULLNAME\n Email = None\n
Shell = $SHELL\n Group = $GROUP\n Home DIR = $HOME\n################################\n\n"

		 echo -e $ADDUSER >> /root/userlist
		 chmod 600 /root/userlist
			 useradd -d $HOME -p $PASS -g $GROUP -s $SHELL $USERNAME
		 mkdir $HOME
		 chown $USER:$GROUP $HOME
		 chmod 700 $HOME

		 ADD=0
	  else

		 # Create the user, add them to the list and email them

		 EMAIL="Blah blah blah blah \n\n  Server = place.home.net\n  Username = $USERNAME\n
Password = $PASS\n\nblah blah blahb blah\n\nThank You\n\nYou You You\n"
		 echo -e $EMAIL >> /root/email
		 chmod 600 /root/email

		 ADDUSER="################################\n Username = $USERNAME\n Password = $PASS\n FullName = $FULLNAME\n Email = $ADDY\n
Shell = $SHELL\n Group = $GROUP\n Home DIR = $HOME\n################################\n\n"
		 echo -e $ADDUSER >> /root/userlist
		 chmod 600 /root/userlist

		 useradd -d $HOME -p $PASS -g $GROUP -s $SHELL $USERNAME
		 mkdir $HOME
		 chown $USER:$GROUP $HOME
		 chmod 700 $HOME


		 cat /root/email | mail -s "User Added to Server" $ADDY
		 rm /root/email
		 ADD=0
	  fi
   else
	  echo "Error!!!"
fi

done

else

echo "You Need To Be Root!"

fi

# reset your signal traps
trap - INT TERM QUIT
exit 0


#2 The7thSim

The7thSim

    Private

  • Members
  • 2 posts

Posted 18 April 2009 - 07:47 AM

This script is great, but it doesn't set the password correctly. If you are going to use the -p flag on useradd you must first encrypt the password or else the user will not be able to log in.

add this:
PASSCRYPTED=$(perl -e 'print crypt($ARGV[0], "password")' $PASS)

and then change the useradd line to this:
useradd -d $HOME -p $PASSCRYPTED -g $GROUP -s $SHELL $USERNAME

-Jerod

#!/bin/bash
 #Add User, Password Generator, Emailer and List maker script :D
 # by typedeaF;; Edited by UmInAsHoE;; Edited by The7thSim
 #<?
 function check() {
 WHEREIS="";
 CHMOD="";
 RM="";
 MAIL="";
 GROUPADD="";
 USERADD="";
 AWK="";
 echo ""
 echo "Searching for dependancies:"
 sleep 3
		 xi=`whereis whereis`;
		 if [ "x$xi" = "x" ]; then
				 echo " [!] Whereis was unable to find itself";
				 exit 1;
		 else
				 xm=0;
				 for xl in $xi; do
						 xm=`expr $xm + 1`;
						 if [ "x$xm" = "x2" ]; then
								 WHEREIS="$xl";
						 fi
				 done
 
				 if [ ! -x $WHEREIS ]; then
						 echo " [!] Whereis can be executed but not found?";
						 exit 1;
				 fi;
		 fi;
 
 AWK=`$WHEREIS awk `;
		 xj=0;
		 for xk in $AWK; do
				 xj=`expr $xj + 1`;
				 if [ "x$xj" = "x2" ]; then
						 AWK="$xk";
				 fi
		 done;
 
		 if [ ! -x $AWK ]; then
				 echo " [!] Awk could not be located. Broken System?";
				 exit 1;
		 fi
 
 
 USERADD=`$WHEREIS useradd | $AWK '{print $2}' - `;
		 if [ "x$USERADD" = "x" ]; then
				 echo " [!] Unable to find useradd. Broken Environment?";
				 exit 1;
		 fi
 
 GROUPADD=`$WHEREIS groupadd | $AWK '{print $2}' - `;
		 if [ "x$GROUPADD" = "x" ]; then
				 echo " [!] Unable to find groupadd. Broken Environment?";
				 exit 1;
		 fi
 
 MAIL=`$WHEREIS mail | $AWK '{print $2}' - `;
		 if [ "x$MAIL" = "x" ]; then
				 echo " [!] Unable to find mail. Broken Environment?";
				 exit 1;
		 fi
 
 RM=`$WHEREIS rm | $AWK '{print $2}' - `;
		 if [ "x$RM" = "x" ]; then
				 echo " [!] Unable to find Rm. Broken Environment?";
				 exit 1;
		 fi
 
 CHMOD=`$WHEREIS chmod | $AWK '{print $2}' - `;
		 if [ "x$CHMOD" = "x" ]; thenjerodfritz@gmail.com
				 echo " [!] Unable to find chmod. Broken Environment?";
				 exit 1;
		 fi
 }
 
 
 
 # Make a semi-random password using an array of user-friendly characters
 function mkpass() {
   PASS=""
   PASSLEN=8
   array1=( q w e r t y u i o p a s d f g h j k l z x c v b n m
	 Q W E R T Y U I O P A S D F G H J K L Z X C V B N M
	 1 2 3 4 5 6 7 8 9 0 \! \@ \# \$ \% \^ \& \*
   )
   MODNUM=${#array1[*]}
 
   count=0
   while [ ${count:=0} -lt $PASSLEN ]
   do
	 number=$(($RANDOM%$MODNUM))
	 PASS="$PASS""${array1[$number]}"
	 ((count++))
   done
 
   echo $PASS
 }
 
 # center the text on the screen by finding the horizontal center with max_lines
 # max_lines divided by two becomes the center line(aka. line_num)
 # use the max lenght of the line divided in half to find the center column
 # subtract half the output string from the center to create the offset to indent
 function center_txt() {
   PROMPT="$1"
   str_len=${#PROMPT}
   indent=$(( ((max_cols / 2)) - ((str_len / 2)) ))
   line_num=$(( max_lines / 2 ))
   tput cup ${line_num} ${indent}
   echo "$PROMPT"
 }
 
 # indent_txt is intended to be used AFTER center_txt
 # indent_txt just prints on the current line and centers the text horizontally
 # line_num is global, so main keeps track of incrementing it
 function indent_txt() {
   PROMPT="$1"
   str_len=${#PROMPT}
   indent=$(( ((max_cols / 2)) - ((str_len / 2)) ))
   tput cup ${line_num} ${indent}
   echo "$PROMPT"
 }
 
 # mk_prompt creates an input prompt for the the read function
 # 'read -p "==> " variable' would work, but I like this better
 function mk_prompt() {
   ((line_num+=2))
   tput cup $line_num 15
   PROMPT="==> "
   echo -n "${blink}${PROMPT}"
   echo -n ${offblink}
 }
 
 # This function gathers all the information needed to generate the useradd string
 function mkuser() {
   USERNAME=""
   FULLNAME=""
   OTHER=""
   GROUP=""
   HOME=""
   SHELL=""
   ADDY=""
 
   echo ${term_clr}
   PROMPT="Enter new users E-mail Address"
   center_txt "$PROMPT"
   ((line_num++))
   PROMPT="(ex. test@test.com or 0 for none)"
   indent_txt "$PROMPT"
   mk_prompt
   read ADDY
 
   echo ${term_clr}
   PROMPT="Enter the new Login account user name"
   center_txt "$PROMPT"
   ((line_num++))
   PROMPT="(ex. xxxxN00b)"
   indent_txt "$PROMPT"
   mk_prompt
   read USERNAME
 
   echo ${term_clr}
   PROMPT="Enter the users Full Name"
   center_txt "$PROMPT"
   ((line_num++))
   PROMPT="(ex. John Doe)"
   indent_txt "$PROMPT"
   mk_prompt
   read FULLNAME
 
   echo ${term_clr}
   PROMPT="Select the users Shell"
   center_txt "$PROMPT"
   ((line_num++))
   PROMPT="(ex. type \"1\" for Bash)"
   indent_txt "$PROMPT"
   ((line_num+=2))
   indent=$(( ((max_cols / 2)) - 6 ))
   tput cup $line_num $indent; ((line_num++)); echo "1) Bash"
   tput cup $line_num $indent; ((line_num++)); echo "2) Other"
   mk_prompt
   read REPLY
 
 case "$REPLY" in
   1)
	 SHELL="$BASH"
;;
   2)
	 echo ${term_clr}
	 PROMPT="Enter a Shell Location for $USERNMAE"
	 center_txt "$PROMPT"
	 ((line_num++))
	 PROMPT="(ex. $BASH)"
	 indent_txt "$PROMPT"
	 mk_prompt
	 read SHELL
;;
   * )
	 echo "Invalid choice"
;;
 esac
 
   echo ${term_clr}
   PROMPT="Select the users Primary Group"
   center_txt "$PROMPT"
   ((line_num++))
   PROMPT="(ex. type \"1\" for Their Username)"
   indent_txt "$PROMPT"
   ((line_num+=2))
   indent=$(( ((max_cols / 2)) - 6 ))
   tput cup $line_num $indent; ((line_num++)); echo "1) Thier Username"
   tput cup $line_num $indent; ((line_num++)); echo "2) Other"
   mk_prompt
   read REPLY
 
   case "$REPLY" in
   1)
	 GROUP="$USERNAME"
	 HOME="/home/$USERNAME"
;;
   2)
	 echo ${term_clr}
	 PROMPT="Enter a Group Name for $USERNMAE"
	 center_txt "$PROMPT"
	 ((line_num++))
	 PROMPT="(ex. Wheel)"
	 indent_txt "$PROMPT"
	 mk_prompt
	 read OTHER
	 GROUP="$OTHER"
	 HOME="/home/$USERNAME"
;;
   * )
	 echo "Invalid choice"
;;
   esac
 }
 # Just reset the terminal to normal
 function _quit() {
   reset -Q
   echo "Exiting Add User Script. Bye"
   exit 0
 }
 
 
 
 # =================================================#
 # Begin Main #
 # =================================================#
 
 #lets check we can execute script
 check
 
 ROOT_UID=0
 
 if [ "$UID" -eq "$ROOT_UID" ]; then
 
 
 # These are the tput commands used to terminal output formatting
 term_clr=$(tput clear)
 max_lines=$(tput lines)
 max_cols=$(tput cols)
 blink=$(tput blink)
 offblink=$(tput sgr0)
 
 let CONTINUE=0
 
 # Set up a trap to handle control signals. If you start using temp files then
 # this is where you would want to clean up.
 trap _quit INT TERM QUIT
 
 ADD=0
 while [ $CONTINUE -eq 0 ]
 do
   if [ "$ADD" = 0 ]; then
   mkuser
   mkpass
   PASSCRYPTED=$(perl -e 'print crypt($ARGV[0], "password")' $PASS)
   echo ${term_clr}
 groups | grep -iw $GROUP
 
   if [ `echo $?` = "0" ]; then
	 echo ${term_clr}
	 PROMPT="User with the following criteria"
	 center_txt "$PROMPT"
	 ((line_num+=2))
	 PROMPT="groupadd $GROUP"
	 indent_txt "$PROMPT"
	 ((line_num+=2))
	 PROMPT="useradd -d $HOME -p $PASSCRYPTED -g $GROUP -s $SHELL $USERNAME"
	 indent_txt "$PROMPT"
	 ((line_num+=2))
 
	 uline=$(tput smul)
	 offuline=$(tput rmul)
	 PROMPT="Password: $PASS"
	 ADD=1
	 str_len=$(( ${#PROMPT} + 8 ))
	 indent=$(( ((max_cols / 2)) - ((str_len / 2)) ))
	 tput cup ${line_num} ${indent}
	 echo -n "${uline}$PROMPT${offuline} "
	 tput cup $max_lines
 
	 PROMPT="Press Return to continue and Add User. Press ^C (ctrl + c) to EXIT."
	 echo -n "${blink}${PROMPT}"
	 echo -n ${offblink}
	 read -s
 
 else
	 echo ${term_clr}
	 PROMPT="User and Group with the following criteria"
	 center_txt "$PROMPT"
	 ((line_num+=2))
	 PROMPT="groupadd $GROUP"
	 indent_txt "$PROMPT"
	 ((line_num+=2))
	 PROMPT="useradd -d $HOME -p $PASSCRYPTED -g $GROUP -s $SHELL $USERNAME"
	 indent_txt "$PROMPT"
	 ((line_num+=2))
 
	 uline=$(tput smul)
	 offuline=$(tput rmul)
	 PROMPT="Password: $PASS"
	 ADD=1
	 str_len=$(( ${#PROMPT} + 8 ))
	 indent=$(( ((max_cols / 2)) - ((str_len / 2)) ))
	 tput cup ${line_num} ${indent}
	 echo -n "${uline}$PROMPT${offuline} "
	 tput cup $max_lines
 
	 PROMPT="Press Return to continue and Add User and Add Group. Press ^C (ctrl + c) to EXIT."
	 echo -n "${blink}${PROMPT}"
	 echo -n ${offblink}
	 ADD=1
	 read -s
 
	fi
 
	elif [ "$ADD" = 1 ]; then
		   #Add the group
		   groupadd $GROUP
	   if [ "$ADDY" = "0" ]; then
 
		  # Create the user and add the user to the list with no email
 
		  ADDUSER="################################\n Username = $USERNAME\n Password = $PASS\n FullName = $FULLNAME\n Email = None\n
 Shell = $SHELL\n Group = $GROUP\n Home DIR = $HOME\n################################\n\n"
 
		  echo -e $ADDUSER >> /root/userlist
		  chmod 600 /root/userlist
			  useradd -d $HOME -p $PASSCRYPTED -g $GROUP -s $SHELL $USERNAME
		  mkdir $HOME
		  chown $USER:$GROUP $HOME
		  chmod 700 $HOME
 
		  ADD=0
	   else
 
		  # Create the user, add them to the list and email them
 
		  EMAIL="Hey ,\n\n I created you a development sandbox with the following information.  This account gives you shell access and a public web site at http://<yourhost>/~$USERNAME/. You can change your password by running the 'passwd' command at the shell prompt after logging in via ssh through your terminal with 'ssh $USERNAME@<yourhost>' .\n\n\thost = <yourhost>\n\tport = 22\n\tuser = $USERNAME\n\tpass = $PASS\n\nThanks,\nJerod"
		  echo -e $EMAIL >> /root/email
		  chmod 600 /root/email
 
		  ADDUSER="################################\n Username = $USERNAME\n Password = $PASS\n FullName = $FULLNAME\n Email = $ADDY\n
 Shell = $SHELL\n Group = $GROUP\n Home DIR = $HOME\n################################\n\n"
		  echo -e $ADDUSER >> /root/userlist
		  chmod 600 /root/userlist
		 
		  useradd -d $HOME -p $PASSCRYPTED -g $GROUP -s $SHELL $USERNAME
		  mkdir $HOME
		  chown $USER:$GROUP $HOME
		  mkdir $HOME/public_html
		  chown $USER:$GROUP $HOME/public_html
		  echo "my homepage" > $HOME/public_html/index.html
		  chmod 755 $HOME $HOME/public_html
		  chmod 755 $HOME/public_html/index.html
		  chmod 711 $HOME
 
		  cat /root/email | mail -s "new account created for you" $ADDY
		  rm /root/email
		  ADD=0
	   fi
	else
	   echo "Error!!!"
 fi
 
 done
 
 else
 
 echo "You Need To Be Root!"
 
 fi
 
 # reset your signal traps
 trap - INT TERM QUIT
 exit 0


#3 The7thSim

The7thSim

    Private

  • Members
  • 2 posts

Posted 18 April 2009 - 08:03 AM

Also you may notice some problems with the chown command on line 376:
chown $USER:$GROUP $HOME

should read:
chown $USERNAME:$GROUP $HOME

#4 webdevil

webdevil

    Retired GSO General

  • Sergeant Major
  • 1,195 posts

Posted 18 April 2009 - 01:19 PM

This is the output from a machine I am currently on...

webDEViL@wD:~$ echo $USERNAME
webDEViL
webDEViL@wD:~$ echo $USER
webDEViL
webDEViL@wD:~$

So I guess it shouldn't be a problem.





Also tagged with one or more of these keywords: server, shell