This script is useful for adding user as a non-root
do one small changes in following configuration file (RED color ----indicate changes )
Code:
vi /etc/sudoers
# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
## See the sudoers man page for the details on how to write a sudoers file.
## Host alias specification
# User alias specification
# Cmnd alias specification
# Defaults specification
# User privilege specification
root ALL=(ALL) ALL
normal_user_name ALL=(ALL) ALL
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
normal_user_name ALL=(ALL) NOPASSWD: ALL
# Samples
# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users localhost=/sbin/shutdown -h now
Actual SCRIPT start here ....................
You can run this script using two method
1.passing arguments
pass the arguments such as user_name passwd and confirm passwd
example: $ sh addftpuser.sh user_name passwd confirm_passwd
2.Without passing arguments
example:
$sh addftpuser.sh
Code:
#!bin/bash
#
##### script for to add a FTP user ########
#### ****************** ANIL RATHOD ************************************************************
ftpPath="/ftp/user/"
SUGROUP="normal_user_name"
USERNAME=$1 #--------- User Name
PASS=$2 #--------- Password
CPASS=$3 #--------- Conformation Passwd
# ftpuser($USERNAME,$PASS,$CPASS) function with three arguments such as Username,passwd and conform passwd
ftpuser()
{
# USERNAME=$1 #--------- User Name
# PASS=$2 #--------- Password
# CPASS=$3 #--------- Conformation Passwd
if [ $PASS = $CPASS ] # Password Conformation
then
########### Adding new user and assign a passwd ##########
sudo mkdir $ftpPath$USERNAME # to create home Directory for User
sudo /usr/sbin/adduser -d $ftpPath$USERNAME $USERNAME
if [ -z $PASS ] # if password argument is null then
then
sudo passwd $USERNAME
sleep 1
else
echo $PASS |sudo passwd --stdin $USERNAME
sleep 1
fi
######### set the permission for group #####
sudo chmod -R 775 $ftpPath$USERNAME
sudo chown -R $USERNAME:$SUGROUP $ftpPath$USERNAME
sudo mkdir $ftpPath$USERNAME/{data,dropbox}
sudo chown -R $USERNAME:$SUGROUP $ftpPath$USERNAME/{data,dropbox}
sudo chmod -R 775 $ftpPath$USERNAME/{data,dropbox}
############## Adding this user into SUPER GROUP ##############
#/usr/sbin/usermod -G $USERNAME $SUGROUP
USERDETAIL=`cat /etc/group | grep $USERNAME`
sudo sed -i "s/$USERDETAIL/$USERDETAIL$USERNAME,user_name" /etc/group
else
echo " Password are not Match .... "
echo "Please Entercorrect password"
fi
}
#********** END OF FUNCTION ****************
############################################
if [ -z $1 ]
then
Inteactive="1"
else
Non_Interactive="1"
fi
###########################################
#******************************************
if [ -e $ftpPath ] # If path is not found
then
if [ "$Inteactive" = "1" ]
then
clear
echo " Are you wany to add new ftp user (y/n)?"
read ANS
until [ $ANS = "n" ]
do
if [ $ANS = "y" ]
then
echo "Enter the FTP user name "
read USERNAME
ftpuser $USERNAME
echo " Are you wany to add new ftp user (y/n)?"
read ANS
else
echo "Sorry !"
fi
done
else if [ "$Non_Interactive" = "1" ]
then
ftpuser $1$2$3
fi
fi
else
echo "Sorry PathftpPath........... not exit "
fi
Anil V.Rathod
Linux System Administrator
Kalinga Data Link Pvt.Ltd.,Pune(MS)
Cell No.9860062917