Skip to content
Snippets Groups Projects

new_user.sh

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by arn2
    Edited
    new_user.sh 733 B
    #!/bin/bash
    
    echo "Enter new username: "
    read USERNAME
    
    echo "Enter disk quota (GB): "
    read QUOTA_SIZE
    
    echo "Enter an expiration date (yyyy-mm-dd or leave blank) : "
    read EXPIRATION_DATE
    
    echo "Enter shell (leave empty for bash): "
    read LOGIN_SHELL
    
    if [[ -z $LOGIN_SHELL ]]
    then
        LOGIN_SHELL="/bin/bash"
        #chage -E $EXPIRATION_DATE
    fi
    
    
    if [[ -z $EXPIRATION_DATE ]]
    then
        EXPIRATION_DATE="None"
        useradd -G developer -s $LOGIN_SHELL $USERNAME
    else
        useradd -G developer -s $LOGIN_SHELL -e $EXPIRATION_DATE $USERNAME
    fi
    
    passwd $USERNAME
    
    chage -d 0 $USERNAME
    
    echo ""
    echo "Creating new user: "
    echo "User: $USERNAME"
    echo "Quota: $QUOTA_SIZE GB"
    echo "Expiration: $EXPIRATION_DATE"
    echo "Login shell: $LOGIN_SHELL"
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment