Return to BSD News archive
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!bruce.cs.monash.edu.au!not-for-mail From: maurice@bruce.cs.monash.edu.au (Maurice D Castro) Newsgroups: comp.unix.bsd Subject: Re: How to add user? Date: 20 Nov 1994 06:59:24 GMT Organization: Computer Science, Monash University, Australia Lines: 211 Message-ID: <3ams4c$jtn@harbinger.cc.monash.edu.au> References: <3ak0mr$q2v@crl.crl.com> <1994Nov19.070927.136197@slate.mines.colorado.edu> NNTP-Posting-Host: dec45.cs.monash.edu.au X-Newsreader: TIN [UNIX 1.3 941028BETA PL0] Ade Barkah (mbarkah@slate.mines.colorado.edu) wrote: : Peter Lam (petelam@crl.com) wrote: : : Does anyone know how to add user in FreeBSD? I tried adduser, but it : : can't find the file. Where is the procedure adduser(8)? How do I use it? : Good question. I don't have it either (FreeBSD 2.0-a). Maybe : it's in a package I haven't installed. Anyhow, to add users : without adduser, you can use vipw and add the home directory : manually. : -Ade Barkah : ps. the adduser manpage is there. =) `find /...' turns out empty. The adduser man page (vaguely) describes the steps required to add a user to a FreeBSD system. The following is my adduser script which is based upon others work and is applicable to FreeBSD release. It can be modified for other systems. Note that two shell scripts are used to simplify the process. #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: addentry adduser adduser.shar # Wrapped by maurice@dec45.cs.monash.edu.au on Sun Nov 20 17:57:41 1994 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f addentry -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"addentry\" else echo shar: Extracting \"addentry\" \(46 characters\) sed "s/^X//" >addentry <<'END_OF_addentry' X#!/bin/sh Xsleep 1 Xcat /tmp/passwdentree >> $1 END_OF_addentry if test 46 -ne `wc -c <addentry`; then echo shar: \"addentry\" unpacked with wrong size! fi # end of overwriting check fi if test -f adduser -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"adduser\" else echo shar: Extracting \"adduser\" \(3528 characters\) sed "s/^X//" >adduser <<'END_OF_adduser' X#!/bin/sh X# X# add user script for use with 386bsd X# arguments: uname uid gid fullname homedir shell X# X# bmyers@rucs2.sunlab.cs.runet.edu X# X# Modified by M. Castro X# X# to execute type: X# sh add_user [uname] [uid] [gid] ["full name"] [homedir] [shell] X Xmyname=`basename $0` XPasswd=/etc/passwd XPATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin Xexport PATH X# check for root Xif [ "`whoami`x" != "root"x ]; then X echo "You must be root to do $myname!" X exit 1 Xfi X X# check for number of args X# Change to 5 if the directories are going to be in the same place X# ie. no homedir option given to the program X Xif [ $# -ne 6 ]; then X echo "${myname}: invalid number of arguments" X echo " usage: ${myname} uname uid gid \"fullname\" homedir shell" X exit 1 Xfi X X# put args into named variables Xuname=$1 Xuid=$2 Xgid=$3 Xfullname=$4 Xhomedir=$5 # If all directories are going to be in the same place Xshell=$6 # Then change homedir=$5 to homedir=/DIR/../$1 ie: /DIR/../UNAME X # homedir will be assumed on each call X X# checks for validity of arguments X# check uid Xif test $uid -lt 10 ; then X echo "uid: uid must be greater than 10 and less than 60000" X exit 1 Xelif test $uid -gt 60000 ; then X echo "uid: uid must be greater than 10 and less than 60000" X exit 1 Xfi X X# check gid Xif test $gid -lt 10 ; then X echo "gid: gid must be greater than 10 and less than 60000" X exit 1 Xelif test $gid -gt 60000 ; then X echo "gid: gid must be greater than 10 and less than 60000" X exit 1 Xfi X X X# check shell Xif test ! -x $shell ; then X echo "$shell: the program does not exist or is not executable" X exit 1 Xfi X X# check homedir X# check if homedir already exists Xif [ -f ${homedir} ]; then X echo "${myname}: WARNING: a file named \"${homedir}\" already exists" X echo "and is NOT a directory, NOT setting up user account" X exit 1 Xfi Xif [ -d ${homedir} ]; then X echo "${myname}: WARNING: home directory \"${homedir}\" already exists" X echo " no files copied, NOT setting up user account" X exit 1 Xfi X# check if all but last path of homedir exits X#dir=`shdirname $homedir` X#if test ! -d $dir ; then X# echo "$dir: does not exist or is not a directory" X# exit 1 X#fi X# check if $homedir is local Xdfout=`df $dir | ( read aline; read aline; echo $aline )` Xcase $dfout in X /dev*) ;; # $dir is on local machine X *) echo "$dir: is not on local machine" X exit 1;; Xesac X X# create a null /etc/passwd entry X# first check if one already exists Xif grep -s "^${uname}:" ${Passwd} ; then X echo "${myname}: ERROR: ${uname} aleady in ${Passwd}"; X exit 1; Xfi X# check if uid already exists Xif grep -s ".*:.*:${uid}:" ${Passwd} ; then X echo "uid: ERROR: ${uid} already in ${Passwd}"; X exit 1; Xfi Xpwent="${uname}::${uid}:${gid}::0:0:${fullname}:${homedir}:${shell}" X# XXX sould we use tmp file and rename it? X XEDITOR=/usr/sbin/addentry Xexport EDITOR X( echo "${pwent}"; ) > /tmp/passwdentree Xvipw ${Passwd} X X# Verify that the entree was saved. Xif grep -s "^${uname}:" ${Passwd} ; then X : Xelse X echo "${myname}: ERROR: password entry didn't go to ${Passwd}"; X exit 1; X rm -f /tmp/passwdentree # remove old file Xfi Xrm -f /tmp/passwdentree # remove old file X X# Set a temporary password so that passwd will work Xpasswd ${uname} X# make the home directory X/bin/mkdir ${homedir} X/usr/sbin/chown ${uname} ${homedir} X/usr/bin/chgrp ${gid} ${homedir} X X# add default user startup files Xfor i in /usr/share/skel/dot.* Xdo cp $i ${homedir}/`basename $i | sed s/dot//` Xdone X/usr/sbin/chown -R ${uname} ${homedir} X/usr/bin/chgrp -R ${gid} ${homedir} X X# is ok, exit 0 Xexit 0 END_OF_adduser if test 3528 -ne `wc -c <adduser`; then echo shar: \"adduser\" unpacked with wrong size! fi # end of overwriting check fi if test -f adduser.shar -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"adduser.shar\" else echo shar: Extracting \"adduser.shar\" \(0 character\) sed "s/^X//" >adduser.shar <<'END_OF_adduser.shar' END_OF_adduser.shar if test 0 -ne `wc -c <adduser.shar`; then echo shar: \"adduser.shar\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of shell archive. exit 0 -- Maurice Castro | "In hardware engineering, Ohm's maurice@bruce.cs.monash.edu.au | law and Maxwell's equations pale | in importance and influence next | to Murphy's Law" Gordon Bell