Results 1 to 4 of 4

Thread: Auto creation of new user in newuser login

  1. #1
    Junior Member cripperz's Avatar
    Join Date
    Dec 2010
    Location
    Singapore, Woodlands
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Auto creation of new user in newuser login

    Hi All,

    i am new to shell scripting. I am also offering free unix shell access where i need a shell script or setup that can just auto create account upon request. It will check if the system have the username, if the user is non-existent, it will proceed to create user as per normal, asking for name and email.

    I hope to get some advise from the seniors and experts here on how i can achieve this.

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,515
    Thanks
    17
    Thanked 813 Times in 511 Posts
    Rep Power
    10

    Default

    Are you using Perl or Bash shell?
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  3. #3
    Contributors jaysunn's Avatar
    Join Date
    Apr 2009
    Location
    NYC - USA
    Posts
    1,029
    Thanks
    165
    Thanked 154 Times in 133 Posts
    Rep Power
    24

    Default

    This sounds like a homework assignment. I only did partial of it. You can get
    the hint in regards to asking for email. good luck.

    However this will work.

    PHP Code:
    #!/bin/bash


    GREP=/bin/grep
    USERADD
    =/usr/sbin/useradd
    PASSWD
    =/usr/bin/passwd

    if [ "$(id -u)" != "0" ]; then
       
    echo "This script must be run as root" 1>&2
       
    exit 1
    fi



    echo "Please enter your name and press [ENTER]:  "

    read name

    # Added from billconners advice.
    $GREP  -${name} /etc/passwd

    if [ $? == ]

    then

        
    echo $name, we have you as a user already" 
    exit 0
    else


        echo 
    $name, please stand by why I create your account"

    $USERADD $name

    fi

    echo "Acount has been created"
    sleep 2

    echo -"Do you want to set a password? [yes or no]: "
    read yno
    case $yno in

            
    [yY] | [yY][Ee][Ss] )
                    echo 
    "Great Here we go"
                    
    $PASSWD $name
                    
    ;;

            [
    nN] | [n|N][O|o] )
                    echo 
    "No , Ok that's fine";
                    exit 
    1
                    
    ;;
            *) echo 
    "Please enter yes or no"
                
    ;;
    esac 

    Code:
    [root@kickstart bin]# ./user_creator.sh 
    Please enter your name and press [ENTER]:  
    jason
    jralph:x:500:500:Jason Ralph:/home/jralph:/bin/bash
    jason, we have you as a user already
    Code:
    [root@kickstart bin]# ./user_creator.sh 
    Please enter your name and press [ENTER]:  
    bill
     bill, please stand by why I create your account
    Acount has been created
    Do you want to set a password? [yes or no]: yes
    Great Here we go
    Changing password for user bill.
    New UNIX password: 
    BAD PASSWORD: it is too short
    Retype new UNIX password: 
    passwd: all authentication tokens updated successfully.
    Last edited by jaysunn; 31st July 2011 at 09:36 PM.

  4. The Following User Says Thank You to jaysunn For This Useful Post:

    pradhans0906 (18th July 2011)

  5. #4
    Member billconner's Avatar
    Join Date
    Jul 2010
    Posts
    90
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Rep Power
    5

    Default Login Script

    Tell grep to be more specific:

    grep :${usrname}: /etc/passwd

    Use the curly braces to include the variable and the colon characters and avoid catching a partial match.

    I suggest you not require the script to run as root. Run it as a regular user, preferably in a chroot environment. Have the script construct the entire /etc/passwd entry and send notification to root of the new entry. The root user can then review the entry and append it to /etc/passwd if it checks out.

    Might get a email address from the user and then email a confirmation message requiring a reply. Once root get the reply he knows that the email account is valid.

    The root user can also parse the email header to see the path from the new user's machine.

    After these checks the new account is appended to /etc/passwd.

    User ID and Group ID can be set using an incrementing variable sent to a count file:

    cnt=(($cnt++))
    echo $cnt > count

    Bill

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. HTML+PHP page for user creation
    By arvnix in forum Coding in General
    Replies: 2
    Last Post: 24th June 2010, 06:40 AM
  2. script to auto login to cisco router ( telnet and SSH)
    By aliadamz2010 in forum Shell scripting
    Replies: 5
    Last Post: 12th June 2010, 03:31 AM
  3. [Solved] Ubuntu Desktop Login As Root User
    By eawedat in forum Ubuntu / Debian
    Replies: 9
    Last Post: 27th February 2010, 09:25 PM
  4. [Solved] User account creation shell script
    By duster in forum Shell scripting
    Replies: 3
    Last Post: 29th January 2010, 07:17 PM
  5. How to change the login shell for Linux user
    By chimu in forum Getting started tutorials
    Replies: 0
    Last Post: 26th January 2007, 07:20 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •