Solved

Adding Users to a Unix System

Posted on 2002-04-06
13
1,578 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 300 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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 20

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
removing nim resources 5 54
how to check for shares on aix 1 80
Remote Change Dates on AIX Automation 7 62
centos commands 6 53
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

773 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