LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-17-2013, 11:57 AM   #1
slufoot80
Member
 
Registered: Nov 2011
Posts: 69

Rep: Reputation: Disabled
Smile add user account to linux using a webpage


I have an bash script that I use to add a user account to the system but what I want is to add the user via webpage how do I do this?.

here is my code below from bash
Code:
STARTM=`date -u "+%s"`
#!/bin/bash 
clear
# Script to add a user to this Linux system
if [ $(id -u) -eq 0 ]; then                                     # check if user is root
        read -p "Enter User Name : " username

        while [ -z $username ]|| egrep -w "^$username" /etc/passwd  1>/dev/null;
        do
        echo -ne "Either user exists or you entered a blank, enter username again: ";read -e  username
        done

        password=`</dev/urandom tr -dc A-Za-z0-9 | head -c8`

        echo -ne "\nPlease Enter your User ID Number: ";read -ern5 uid
        while [[ ! $uid =~ ^[0-9]+$ ]]||egrep $uid /etc/passwd >/dev/null; do
        echo -ne "Please re-enter your uid positive intergers only: ";read -ern5 uid
        done

        read -p "Enter a Comment : " comment

        read -p "Enter Users Home Directory : " homedir
        while [ ! -d "$homedir" ];
        do
        echo -ne "\n$homedir Directory Not Found! Please re-enter: "; read homedir
        done        

pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) # passing the password entered
echo ""
                echo "Select the type of shell you will be using"
echo""
echo -e "1) Bash Shell - SFTP Secure\n"                         # Shell selection statement
echo -e "2) False Shell - FTP Unsecure\n"
echo -ne "Enter choice: ";read shell;
case $shell in
1)
        shell=/bin/bash                                                 # case statment for shell selection.
        commentstatic="SFTP Account" 
        useradd -u $uid -p $pass -c "$comment $commentstatic" -d $homedir -s $shell $username
        echo -e "Copying System Files ...."
        cd /usr/local/T_Skel
        cp -Rp `ls` $homedir
        echo -e "Finished Copying System Files ..."
        tail -1 /etc/passwd > $homedir/etc/passwd
        echo "$username" >> /etc/ftpusers
        ssh -q root@ftp2 "echo -e '"$username"' >> /etc/ftpusers"
        ;;
2)
        shell=/bin/false
        commentstatic="FTP Account" 
        useradd -u $uid -p $pass -c "$comment $commentstatic" -d $homedir -s $shell $username
        ;;
esac
        echo "Setting security on users home directory"
        chown $username:ftp $homedir                                    # security settings for both shells
        chmod 775 $homedir
        echo -e "$username" '\t' "$homedir" >> /etc/security/chroot.conf

        echo "Sending information to FTP2"                              # sending information to failover server
        ssh -q root@ftp2 "useradd -u $uid -c '"$comment  $commentstatic"' -p $pass  -d $homedir -s $shell $username"
        ssh -q root@ftp2 "echo -e '"$username"' '\t' '"$homedir"' >> /etc/security/chroot.conf"
clear
echo -e "\n\tThis users login details is as follows: \n"
echo -e "\n\tUsername is: $username \n"
echo -e "\tPassword is: $password \n"
echo -e "\tUser's ID Number is: $uid \n"
echo -e "\tComment is: $comment $commentstatic \n"
echo -e "\tUsers Home Directory is: $homedir \n"
echo -e "\tUsers Shell is: $shell \n"
fi
STOPM=`date -u "+%s"`
RUNTIMEM=`expr $STOPM - $STARTM`
if (($RUNTIMEM>59)); then
TTIMEM=`printf "%dm%ds\n" $((RUNTIMEM/60%60)) $((RUNTIMEM%60))`
else
TTIMEM=`printf "%ds\n" $((RUNTIMEM))`
fi

echo -e "\tExecuting "script function" took: $TTIMEM\n"
 
Old 07-17-2013, 12:08 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
The problem is security.

Anytime you use a web server to perform system functions (especially those that change configuration or add/change/remove users) you run the risk of giving your system away. Anything that can add a user, can also alter system files.

Then you have the issue of the system itself.

RH based systems rigorously isolate the web server from being able to perform such dangerous tasks.

for a base system, it is just a CGI using a suid program (danger) to apply the change... or an expect script with an embedded system password (way more danger) to run the current utilities to do so.

You would do better to use LDAP to put the login definitions elsewhere.
 
  


Reply

Tags
bash, linux, web, webpage


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I add a user account in antiX? newbiesforever MEPIS 7 07-26-2011 06:10 PM
How to add user account(non-root)? cola Slackware 9 09-16-2009 08:13 PM
"To add a new user account, log in to the root account" how do i do this (im new) pierce77x Linux - Newbie 4 12-28-2008 03:44 PM
add user account with pass from script juanctes Linux - General 3 02-03-2008 02:50 PM
samba - add user script - User account does not exist itzamecwp Linux - Server 2 01-18-2007 11:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration