View previous topic :: View next topic |
Author |
Message |
Sasun n00b
Joined: 07 May 2002 Posts: 15
|
Posted: Mon May 13, 2002 8:47 pm Post subject: Red Hat alike useradd shell script |
|
|
Personly, I like the private usergroup scheme of RedHat. This is a simple script wich provides this:
#!/bin/bash
#
# rhuseradd.sh <username> [<group1> [[<group2>] ....<groupn>]]
# this script will choose /bin/bash as user's shell,
# will create primary user group with the same name,
# will create a home folder
# and will add this user to the list of additional groups:
# <group1> ....<groupn>
#
USERADD=/usr/sbin/useradd
GROUPADD=/usr/sbin/groupadd
SHELL=/bin/bash
user=${1}
group=${1}
shift
ag= #additional groups
for grp in ${@}; do
[ -z ${ag} ] && \
ag=${grp} || \
ag=${ag},${grp}
done
# create a primary group with name equal to username
${GROUPADD} ${group}
if [ ${?} -eq 0 ]; then
if [ ! -z ${ag} ]; then
${USERADD} -m -g ${group} -G ${ag} -s ${SHELL} ${user}
else
${USERADD} -m -g ${group} -s ${SHELL} ${user}
fi
fi |
|
Back to top |
|
|
klieber Bodhisattva
Joined: 17 Apr 2002 Posts: 3657 Location: San Francisco, CA
|
Posted: Mon May 13, 2002 9:19 pm Post subject: |
|
|
Cool script! Correct me if I'm wrong, but wouldn't you also want to chown the home directory to be owned by the corresponding private group? Or does it pick this up automatically?
--kurt _________________ The problem with political jokes is that they get elected |
|
Back to top |
|
|
Sasun n00b
Joined: 07 May 2002 Posts: 15
|
Posted: Wed May 15, 2002 8:44 pm Post subject: |
|
|
klieber wrote: | Cool script! Correct me if I'm wrong, but wouldn't you also want to chown the home directory to be owned by the corresponding private group? Or does it pick this up automatically?
--kurt |
Yep it does chown username.username the home folder. |
|
Back to top |
|
|
Sasun n00b
Joined: 07 May 2002 Posts: 15
|
Posted: Sat Oct 12, 2002 5:06 pm Post subject: |
|
|
of cource there was an error in this script. this one is better. one of these day I must learn shell
Code: |
#!/bin/bash
#
# rhuseradd.sh <username> [<group1> [[<group2>] ....<groupn>]]
# this script will choose /bin/bash as user's shell,
# will create primary user group with the same name,
# will create a home folder
# and will add this user to the list of additional groups:
# <group1> ....<groupn>
#
USERADD=/usr/sbin/useradd
GROUPADD=/usr/sbin/groupadd
SHELL=/bin/bash
user=${1}
group=${1}
shift
ag= #additional groups
for grp in ${@}; do
if [ -z "${ag}" ]; then
ag=${grp}
else
ag=${ag},${grp}
fi
done
# create a primary group with name equal to username
${GROUPADD} ${group}
if [ ${?} -eq 0 ]; then
if [ ! -z ${ag} ]; then
${USERADD} -m -g ${group} -G ${ag} -s ${SHELL} ${user}
else
${USERADD} -m -g ${group} -s ${SHELL} ${user}
fi
fi
|
|
|
Back to top |
|
|
splooge l33t
Joined: 30 Aug 2002 Posts: 636
|
Posted: Sat Oct 12, 2002 9:27 pm Post subject: |
|
|
This is exactly what I was looking for. This should be implemented in the 1.4 release!
In my not so humble opinion, this somewhat common practice is a bad idea. If each user is added to the 'users' group, and all homedirs also belong to the 'users' group, then if a user isn't careful, every other user can peek into that user's homedir. A better solution is to create a group for each user, typically with the same group name as user name, and make that the user's primary group. |
|
Back to top |
|
|
yokem55 Guru
Joined: 18 Apr 2002 Posts: 360 Location: Oregon
|
Posted: Tue Oct 15, 2002 9:02 am Post subject: |
|
|
superadduser should do this job just fine. Simply emerge superadduser and the script will install and is ready to run.... |
|
Back to top |
|
|
pjp Administrator
Joined: 16 Apr 2002 Posts: 20499
|
Posted: Thu Oct 24, 2002 6:59 pm Post subject: |
|
|
superadduser appears to only be interactive, which is less than ideal for many situations. _________________ Quis separabit? Quo animo? |
|
Back to top |
|
|
|