I wouldn't suggest doing it any other way, since that's the point of how
security is set up on Linux. Is this script part of a larger project? If
not, what's wrong with the built-in useradd?


Jeremiah E. Bess
Network Ninja, Penguin Geek, Father of five.

<https://plus.google.com/u/0/103182072532361592558>
<http://www.linkedin.com/profile/view?id=47451026>


On Tue, Sep 3, 2013 at 10:31 AM, vinay kumar <[email protected]> wrote:

> I tried like this
> useradd -m -p $pass $username .It is working fine.But problem is that it
> is asking for sudo password.How I would assign sudo password  at the
> running of the shell script.
>
> #!/bin/bash# Script to add a user to Linux systemif [ $(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!"
>       fielse
>       echo "Only root may add a user to the system"
>       exit 2
> fi
>
>
> Here only root can add the user to linux.It asks for the sudo password.How 
> would assign the password.help me out of this I am kind of stuck here
>
>  --
> --
> You received this message because you are subscribed to the Linux Users
> Group.
> To post a message, send email to [email protected]
> To unsubscribe, send email to [email protected]
> For more options, visit our group at
> http://groups.google.com/group/linuxusersgroup
> References can be found at: http://goo.gl/anqri
> Please remember to abide by our list rules (http://tinyurl.com/LUG-Rulesor
> http://cdn.fsdev.net/List-Rules.pdf)
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Linux Users Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
You received this message because you are subscribed to the Linux Users Group.
To post a message, send email to [email protected]
To unsubscribe, send email to [email protected]
For more options, visit our group at 
http://groups.google.com/group/linuxusersgroup
References can be found at: http://goo.gl/anqri
Please remember to abide by our list rules (http://tinyurl.com/LUG-Rules or 
http://cdn.fsdev.net/List-Rules.pdf)

--- 
You received this message because you are subscribed to the Google Groups 
"Linux Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to