Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Red Hat alike useradd shell script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Sasun
n00b
n00b


Joined: 07 May 2002
Posts: 15

PostPosted: Mon May 13, 2002 8:47 pm    Post subject: Red Hat alike useradd shell script Reply with quote

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
View user's profile Send private message
klieber
Bodhisattva
Bodhisattva


Joined: 17 Apr 2002
Posts: 3657
Location: San Francisco, CA

PostPosted: Mon May 13, 2002 9:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
Sasun
n00b
n00b


Joined: 07 May 2002
Posts: 15

PostPosted: Wed May 15, 2002 8:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
Sasun
n00b
n00b


Joined: 07 May 2002
Posts: 15

PostPosted: Sat Oct 12, 2002 5:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
splooge
l33t
l33t


Joined: 30 Aug 2002
Posts: 636

PostPosted: Sat Oct 12, 2002 9:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
yokem55
Guru
Guru


Joined: 18 Apr 2002
Posts: 360
Location: Oregon

PostPosted: Tue Oct 15, 2002 9:02 am    Post subject: Reply with quote

superadduser should do this job just fine. Simply emerge superadduser and the script will install and is ready to run....
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20499

PostPosted: Thu Oct 24, 2002 6:59 pm    Post subject: Reply with quote

superadduser appears to only be interactive, which is less than ideal for many situations.
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum