![]() |
s i s t e m a o p e r a c i o n a l m a g n u x l i n u x | ~/ · documentação · suporte · sobre |
Next
Previous
Contents
7. Putting the Shadow Suite to use.This section discusses some of the things that you will want to know now that you have the Shadow Suite installed on your system. More information is contained in the manual pages for each command.
7.1 Adding, Modifying, and deleting usersThe Shadow Suite added the following command line oriented commands
for adding, modifying, and deleting users. You may also have installed the
useraddThe The first thing that you should do is to examine the default settings and make changes specific to your system:
GROUP=1 HOME=/home INACTIVE=0 EXPIRE=0 SHELL= SKEL=/etc/skel The defaults are probably not what you want, so if you started adding users now you would have to specify all the information for each user. However, we can and should change the default values. On my system:
Now running GROUP=100 HOME=/home INACTIVE=0 EXPIRE=60 SHELL=/bin/bash SKEL=/etc/skel Just in case you wanted to know, these defaults are stored in the file
Now you can use
This will create the following entry in the /etc/passwd file:
And the following entry in the /etc/shadow file:
fred 's home directory will be created and the contents of
/etc/skel will be copied there because of the -m switch.
Also, since we did not specify a UID, the next available one was used.
Changing password for fred Enter the new password (minimum of 5 characters) Please use a combination of upper and lower case letters and numbers. New Password: ******* Re-enter new password: ******* Now the /etc/shadow will contain:
And fred will now be able to login and use the system. The nice
thing about useradd and the other programs that come with the
Shadow Suite is that they make changes to the /etc/passwd
and /etc/shadow files atomically. So if you are adding a user, and
another user is changing their password at the same time, both operations
will be performed correctly.
You should use the supplied commands rather than directly editing
Here is a small interactive script that adds users using #!/bin/bash # # /sbin/newuser - A script to add users to the system using the Shadow # Suite's useradd and passwd commands. # # Written my Mike Jackson <mhjack@tscnet.com> as an example for the Linux # Shadow Password Howto. Permission to use and modify is expressly granted. # # This could be modified to show the defaults and allow modification similar # to the Slackware Adduser program. It could also be modified to disallow # stupid entries. (i.e. better error checking). # ## # Defaults for the useradd command ## GROUP=100 # Default Group HOME=/home # Home directory location (/home/username) SKEL=/etc/skel # Skeleton Directory INACTIVE=0 # Days after password expires to disable account (0=never) EXPIRE=60 # Days that a passwords lasts SHELL=/bin/bash # Default Shell (full path) ## # Defaults for the passwd command ## PASSMIN=0 # Days between password changes PASSWARN=14 # Days before password expires that a warning is given ## # Ensure that root is running the script. ## WHOAMI=`/usr/bin/whoami` if [ $WHOAMI != "root" ]; then echo "You must be root to add news users!" exit 1 fi ## # Ask for username and fullname. ## echo "" echo -n "Username: " read USERNAME echo -n "Full name: " read FULLNAME # echo "Adding user: $USERNAME." # # Note that the "" around $FULLNAME is required because this field is # almost always going to contain at least on space, and without the "'s # the useradd command would think that you we moving on to the next # parameter when it reached the SPACE character. # /usr/sbin/useradd -c"$FULLNAME" -d$HOME/$USERNAME -e$EXPIRE \ -f$INACTIVE -g$GROUP -m -k$SKEL -s$SHELL $USERNAME ## # Set password defaults ## /bin/passwd -n $PASSMIN -w $PASSWARN $USERNAME >/dev/null 2>&1 ## # Let the passwd command actually ask for password (twice) ## /bin/passwd $USERNAME ## # Show what was done. ## echo "" echo "Entry from /etc/passwd:" echo -n " " grep "$USERNAME:" /etc/passwd echo "Entry from /etc/shadow:" echo -n " " grep "$USERNAME:" /etc/shadow echo "Summary output of the passwd command:" echo -n " " passwd -S $USERNAME echo "" Using a script to add new users is really much more preferable than editing
the For more information on the
usermodThe Let's say that you want to change
Now fred 's /etc/passwd file entry would be change to this:
Let's make fred 's account expire on 09/15/97:
Now fred 's entry in /etc/shadow becomes:
For more information on the
userdel
The -r causes all files in the user's home directory to be removed
along with the home directory itself. Files located in other file system
will have to be searched for and deleted manually.
If you want to simply lock the account rather than delete it, use the
7.2 The passwd command and passwd aging.The
For example, let look again at
This means that fred 's password is valid, it was last changed on
03/04/96, it can be changed at any time, it expires after 60 days, fred will
not be warned, and and the account won't be disabled when the password
expires.
This simply means that if If we decide that we want to warn
Now fred is changed to:
For more information on the passwd command see the online manual
page.
7.3 The login.defs file.The file
The
From the above list you can see that this is a rather important file, and you should make sure that it is present, and that the settings are what you desire for your system.
7.4 Group passwords.The If you define this constant and then compile, you must create an
When you created the To create the initial
Once you create new groups, they will be added to the The programs The format of the
Where:
The format of the
Where:
The command The groups password can be changed using the Despite the fact that there is not currently a manual page for
7.5 Consistency checking programs
pwckThe program
It will also warn of any account that has no password. It's a good idea to run
grpck
It also has the
7.6 Dial-up passwords.Dial-up passwords are another optional line of defense for systems that allow
dial-in access. If you have a system that allows many people to connect
locally or via a network, but you want to limit who can dial in and connect,
then dial-up passwords are for you. To enable dial-up passwords, you must
edit the file Two files contain the dial-up information, The second file is the If a user logs into a line that is listed in Another useful purpose for using dial-up passwords might be to setup a line that only allows a certain type of connect (perhaps a PPP or UUCP connection). If a user tries to get another type of connection (i.e. a list of shells), he must know a password to use the line. Before you can use the dial-up feature, you must create the files. The command
Next Previous Contents |