LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   /etc/passwd & /etc/shadow (https://www.linuxquestions.org/questions/linux-general-1/etc-passwd-and-etc-shadow-742094/)

a7mlinux 07-22-2009 07:15 PM

/etc/passwd & /etc/shadow
 
is there a way to append a username and a password from an external file to /etc/passwd for the username and /etc/shadow for the password.
thanks in advance

a7mlinux 07-22-2009 07:27 PM

I found this shell script:
Code:

#!/bin/bash
# Script to add a user to Linux system
# -------------------------------------------------------------------------
# Copyright (c) 2007 nixCraft project <http://bash.cyberciti.biz/>
# This script is licensed under GNU GPL version 2.0 or above
# Comment/suggestion: <vivek at nixCraft DOT com>
# -------------------------------------------------------------------------
# See url for more info:
# http://www.cyberciti.biz/tips/howto-write-shell-script-to-add-user.html
# -------------------------------------------------------------------------
if [ $(id -u) -eq 0 ]; then
        read -p "Enter username : " username
        read -s -p "Enter password : " password
        egrep "^$username" /etc/passwd >/dev/null
        if [ $? -eq 0 ]; then
                echo "$username exists!"
                exit 1
        else
                pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
                useradd -m -p $pass $username
                [ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
        fi
else
        echo "Only root may add a user to the system"
        exit 2
fi

can I execute this script with a shell_exec() php fuction, and I want to pass $pass and $username from a HTML textfields. if I can, HOW?

a7mlinux 08-02-2009 12:19 PM

I'm still need help to solve this problem


All times are GMT -5. The time now is 08:38 PM.