nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Add normal user / FTP user usein NORMAL user(non-root)

This is a discussion on Add normal user / FTP user usein NORMAL user(non-root) within the Shell scripting forums, part of the Development/Scripting category; This script is useful for adding user as a non-root do one small changes in following configuration file (RED color ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 12-07-2007, 06:04 PM
anilvrathod's Avatar
Junior Member
User
 
Join Date: Dec 2007
Location: Pune
My distro: Red Hat
Posts: 13
Rep Power: 0
anilvrathod is on a distinguished road
Arrow Add normal user / FTP user usein NORMAL user(non-root)

This script is useful for adding user as a non-root

do one small changes in following configuration file (RED color ----indicate changes )
Code:

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:

Code:
  vi 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

Last edited by anilvrathod; 12-11-2007 at 01:14 PM.
Reply With Quote
Sponsored Links
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Block Single User Login using root password sayan4u86 Networking, Firewalls and Security 0 09-28-2007 06:47 AM
Prevent root user from being able to log in via SSH service' swillet HP-UX 2 07-17-2007 07:33 PM
how to reset root and user passwords - new install forlornhope Linux software 2 07-05-2007 12:51 AM
how to enable a user and disabling a user narasimha.reddygnv Shell scripting 1 03-31-2007 12:31 AM
Linux Mount a USB flash or pen drive as a normal user charvi Getting started tutorials 1 06-26-2006 07:21 PM


All times are GMT +5.5. The time now is 04:24 AM.


Powered by vBulletin® Version 3.7.3 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36