Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding Users to a Unix System

Posted on 2002-04-06
13
Medium Priority
?
1,594 Views
Last Modified: 2013-12-27
I am trying creat a script that allows me to add user to a certain staion.  Here are the requirements.  
1.  Log in as root(no prblem there)
2.  cd to cd/etc (directory)
3.  co -l passwd (checks out and locks the passwd file for revision control)
5.  vi passwd(edits the file)
6.  / next(Search for the word next)
7.  yy p(This copy the line)
8.  Then I edit the original line.(the username should be first 7 characters of the last name and the first character of the first name.
9.  Save and exit the passwd file.
10. ci -u passwd(checks in and unlocks the passwd file)
11.  Be able to log how use the file last
12.  mkdir username(make a dir with the new user name)
13.  chmod username(change the permission of the users home directory)
14.  cd /home/users/username(this changes directory to the users home directory)
15. ./home/users/(this part has to beable to setup the user enviroment(this creates the users enviroment)
16. pwconv( this adds the new users form the /etc/passwd file to the /etc/shadow file so that the passwd can be created.)
17. passwd username (changes the user password)
18. create a file that copies the passwd and the shadow files to different unix servers.

How can I do all of this?  I think the process is too long?  Help me.


I pretty new at this so please try to explain with as much details as you can.  The simpler you can make this for me the better.  Because I am a new kid on the block when it comes to unix.  Is there any way I can do the following task in a menu driven format?  For example; when I log is as root, I can type the name of a script to run, then it would ask me to add a user, the user name, the dir name, and such and such.  Then send the user infor to the other unix stations.
0
Comment
Question by:UnixKid
  • 3
  • 2
  • 2
  • +6
13 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 1200 total points
ID: 6923196
#!/bin/sh
if [ $# -lt 2 ]; then
   exit 1
fi
\cd  /etc
f=`\echo $1|\cut -c 1,1`
l=`\echo $2|\cut -c 1-7`
u="$f$l"
i=`awk -F: '{u[$3]=1}END{for (i=1000;i<65534;i++){if (u[i]==0){print i;exit}}}' passwd`
g=500
\grep -q ^$u passwd
if [ $? -eq 0 ]; then
   \echo $u already exists
   exit 2
fi
\co -l passwd
\echo "$u:x:$i:$g:$1 $2:/home/users/$u:/usr/bin/tcsh" >> passwd
\ci -u passwd
# 11.  Be able to log how use the file last
\mkdir /home/users/$u
\chown $i:$g /home/users/$u
# 15. ./home/users/(this part has to beable to setup the user enviroment(this creates the users enviroment)
\pwconf
\passwd $u      # keep in mind that this ask interactive
# 18. create a file that copies the passwd and the shadow files to different unix servers.
# just one example (requires ssh setup properly):
\scp passwd different_unix_servers:/etc/passwd
\scp shadow different_unix_servers:/etc/shadow
exit

# chmod 555 above script, execute as root and enjoy;-)
0
 
LVL 15

Expert Comment

by:samri
ID: 6923902
isn't it easier if we stick to Solaris Admintools, or some other WebBased Admin tool like Webmin (http://www.webmin.com/webmin/)

just a suggestion.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6923990
might be easier, I thought about it too, but Admintool laks a revision control (SCCS, RCS, or whatever)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 38

Expert Comment

by:yuzh
ID: 6924419
hi ahoffmann,

   if you copy both /etc/passwd and and /etc/shadow to the
other box, it end up the aother box has the same user accout as the workstation you creadted the new account.

   what do you just save the new entry to a text file. and then just append the usr record to the passwd and shadow files.

    UnixKid, if you look after many UNIX boxes in your next work, and you want to save you time, try to set up NIS+, or NIS ( I perfer to use NIS+).

   cheers!

=================
yuzh


0
 
LVL 2

Expert Comment

by:festive
ID: 6924431
some of what you are doing is better done with
"usermod".

you can spcify a user directory to create
with the -d and -m flags:

ie
useradd -c "User comment or GCOS" -d /home/newuser -g group -m -k /etc/skel -s /bin/sh newuser

/etc/skel contains standard profiles etc - you can set one of these up for each user type - eg:

/etc/skel/finance/
/etc/skel/admin/

similar things can be done with usermod for existing users.

as for change control - the files : /etc/passwd and /etc/shadow are backed up prior to update.
ie /etc/oshadow /etc/opasswd.

Locking is handled by the OS.
If you must have versioning then run the command
with your SCCS or RCS checkout prior to the useradd/usermod
and then check it in after.


if you have access to EXPECT - you can change
passwords etc programatically.

ie something like:

# Run as root

set timeout 20
spawn passwd $USERID
expect {
    -re "(does not exist)|(denied)" {
        send_user "user does not exist, or access denied\n"
        exit 1
        }
    }

expect "password: "
send   "$PASS\r"
expect "password: "
send   "$PASS\r"
expect "successfully changed"
send_user "Password Changed for $USERID"
exit 0

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6924640
> .. and then just append the usr record to ..

then I'll have no check for duplicate account names and duplicate UIDs, see my script.

NIS might solve the problem of keeping passwd in sync, but does not create the home directory (which should be on NFS, I suggest)
0
 
LVL 3

Expert Comment

by:elfie
ID: 6924891
interesting discussion for a course (just listening)
0
 
LVL 38

Expert Comment

by:yuzh
ID: 6925108
use NIS+, and setup auto_home, so the user's home dir can be mounted across to all the boxes in the next work. (Of course, the machine where the user real home located need to be a NFS server, in this case, this will save a lof of work).

0
 

Expert Comment

by:husky_man
ID: 6946089
How many servers? Have you thought about using "rdist" to keep all the password / shadow files identical?
0
 

Author Comment

by:UnixKid
ID: 6960278
Look I don't know much about unix so make it simple.  I need something nice and clean.  Any good books that I can read to help me learn this stuff
0
 
LVL 2

Expert Comment

by:festive
ID: 6961513
"Essential System Administration" covers many flavours of unix in a very readable and well-written way:
ISBN 1-56592-127-5

"Unix in a nutshell" is the ideal companion book with an explanation of commands and how they are used:

Both books have online content available at the O'Reilly and Associates site : www.ora.co

Enjoy.
0
 
LVL 21

Expert Comment

by:tfewster
ID: 8052641
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- Answered by ahoffmann

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8099605
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question