Typo
[linux_from_scratch_hints.git] / OLD / shadowpasswd_plus.txt
blobe9e70f89b38fd73c0f101d3b623518a824879f6a
1 TITLE:          Shadow Suite for Linux(tm) - installation, usage, enhancement
2 LFS VERSION:    3.0+
3 AUTHOR:         Jeffrey Allen Neitzel <jan@belvento.org>
5 SYNOPSIS:
6         Do you want to know your system is secured with regard to passwords?
7         Do you want to learn more about security?
8         Understanding the usage of passwords on your system is a good place
9         to start since passwords on UNIX(tm) are analogous to the keys for
10         the front door of your home. Shadow Passwords can help to keep these
11         keys from falling into the wrong hands.
13 HINT:
15 2001-10-09
17 Table of Contents
18         Preface
19         Introduction
20                 *) Two Approaches
21                 *) Terminology
22         Chapter 1
23                 - Preliminary Information
24                   *) What is password shadowing?
25                   *) Am I already using it?
26                   *) DES vs. MD5 passwords?
27                   *) Do I want to shadow my password file?
28         Chapter 2
29                 - Installing Shadow-20001016
30                   *) Installation Commands
31         Chapter 3
32                 - Additional Configuration/Security Steps
33                   *) How do I add a new user?
34                   *) /etc/login.defs (configuring the shadow login suite)
35                   *) Essential Permissions
36         Chapter 4
37                 - Conclusion
38         Footnotes
41 ==============================================================================
42   PREFACE
43 ==============================================================================
45 All of the following modifications and suggestions are based on the
46 installation commands as they appear in:
48         Linux From Scratch: Version 3.0 (lfs-3.0)
50 The suggestions here will apply directly to any LFS System which uses the
51 shadow password suite (shadow-20001016) as obtained from:
52 ftp://ftp.pld.org.pl/software/shadow/
54 Please refer to the DISCLAIMER at
55 http://hints.linuxfromscratch.org/hints/DISCLAIMER
57 In addition, the author takes no responsibility for the security of your system.
58 These are friendly suggestions, but it should not be forgotten that implementing
59 security measures for your site is multifaceted. Password security is only one
60 part of that.
62 I assume you are installing the shadow password suite now. You will need
63 super-user (root) privileges to perform many of the system-wide configuration
64 activities discussed here. This document assumes you have these privileges.
65 Because of this, I must leave you with one final thought, "Think before you
66 type."
69 ==============================================================================
70   INTRODUCTION
71 ==============================================================================
73 The primary objective of this document is to complement and extend the LFS BOOK
74 in regards to shadow passwords on your LFS System. I will try to detail some
75 additional steps to take which can help enhance system security. In doing so,
76 I hope the reader finds this to be a valuable extension to the book's methods.
78 o== Two Approaches ==o
80 I have tried to split the commands to address both, those individuals who are
81 doing the book and reading this document concurrently, and those who are reading
82 this after they have already finished the book. To achieve this, the author will
83 use the following notations in Chapters 2, 3, and 4:
85   # Approach 1
86     will allow the reader to replace commands for installing Shadow-20001016
87     as found in the book with commands listed here.
89   # Approach 2
90     will be primarily for those individuals who have already installed
91     Shadow-20001016 previously and now want to check their configuration
92     to be sure all is well, upgrade, modify, etc.
94   # BOTH 1+2
95     will apply to both sets of readers.
97 o== Terminology ==o
99 I will use the terms password, passphrase, and secret interchangeably. Also,
100 rather than use the word "encrypted" to describe the string your password gets
101 turned into, I will say "encoded" instead. This is because the password you type
102 actually gets encoded using a one way hash function. See crypt(3) for more info.
103 I believe the same holds true for MD5-based passwords.
107 I hope to extend on what I have written here as time permits, and I invite the
108 reader to contact me to report errors and/or omissions. Of course, all comments
109 and questions are welcome.
111 To begin, I should preface all of the following with the fact that when it
112 comes to security and computers there is *always* a balancing act between
113 security (paranoia) and convenience, for both system administrators and
114 users alike.
116 Because of this need for compromise and balance, interpretation of security
117 requirements differs from site to site. Interpretation of suggested practice
118 will usually fall victim to the subjectives inherent in human nature.
120 On that note, this author approaches security from the PARANOID perspective.
121 Reader should balance these suggestions with his/her own need for convenience.
122 If the suggestion introduces too much inconvenience relative to added security
123 benefit, I invite you to interpret and implement as your needs dictate.
125 References will be made when necessary to explain more fully about a particular
126 topic.
129 ==============================================================================
130   Chapter 1 - Preliminary Information
131 ==============================================================================
133 o== What is password shadowing? ==o
135 Password shadowing is a useful tool and one part of securing your system. It is
136 a tool to allow protecting password information from those who really have no
137 need to see it. Since reams of information exist about passwords and computer
138 security I won't go on to duplicate any of it here.
140 In short, shadowing your password file consists of removing the encoded secrets
141 from the necessarily world-readable /etc/password file and instead placing them
142 into another file which is not world-readable. This other file is normally
143 called /etc/shadow on Linux systems.
145 It is an idea which is not necessarily new and has been implemented in one way
146 or another on a great many UNIX systems. The Shadow Suite for Linux is one of
147 these tools. It is only a tool, not security salvation.
149 o== Am I already using it? ==o
151 Have you already run the `/usr/sbin/pwconv' command? Have you already given
152 root a password by running `/usr/bin/passwd root'? If so, the answer is most
153 likely, "YES".
155 I say "most likely" because I feel that you can never be too certain with
156 something this important to the integrity of your system. So, on that note,
157 please take a moment now to examine the relevant files if you have not done
158 this already.
160 For more information on the following please refer to the relevant man pages
161 which would be:
162 PASSWD(5) get there with `man 5 passwd' and/or,
163 SHADOW(5) get there with `man 5 shadow'.
165 For each line in /etc/password, you should see something like this:
167   username:password:uid:gid:comment:home_directory:user_shell
169 The fields are delimited by colons. Field number 2 is the password field.
170 One of the following will be true:
172   *) password field contains nothing (e.g. username::uid)
174      This is a sign of danger! DANGER! You have no password. Please stop now
175      and give yourself a password.
177   *) password field contains "x"
179      If you see an "x" there this normally means that shadow passwords have
180      been enabled. In such case, your encoded password has moved to the shadow
181      password file (/etc/shadow). If you are the super-user, now might be a
182      good time to go ahead and look at what is in this file. Be sure there is
183      an entry in /etc/shadow for each user in /etc/password. There are occasions
184      where some users in the password file might be missing from the shadow
185      file. This is most likely to happen if you have ever added a user with
186      the vipw program.
188   *) password field contains "a_bunch_of_ASCII_characters"
190      If you see a bunch of ASCII characters instead of an "x", then you are not
191      using shadow passwords. The ASCII characters make up the encoded string
192      which represents your password.
194 o== DES vs. MD5 passwords? ==o
196 There are two different algorithms *commonly* used to encode user passwords.
197 One of them uses the crypt function which uses a DES-based algorithm. The
198 other method uses a MD5-based algorithm which is substantially better than
199 the DES method. There *are* others, but these two are the ones currently
200 available on Linux.
202 Which one am I using?
203 You can distinguish one from the other by looking at the encoded password
204 string. If it begins with $1$ and is 34 characters long including the $1$,
205 this is an MD5-based ciphertext format. DES-based formats are substantially
206 shorter, about 13 characters in length if I recall.
208 o== Do I want to shadow my password file? ==o
210 Yes, you do! It should be noted, however, that there are apparently some
211 situations where you might not want to do this. Since I personally cannot speak
212 of these situations I must defer to the experience of others in this regard.
213 On the other hand, if your machine is one with user accounts on it (a desktop
214 workstation for example) and doesn't mess around with NFS and the like, then
215 shadowing your password file certainly can't hurt. In the end of course, it's
216 entirely up to you.
218 Suffice it to say that on any UNIX system passwords are an important part of
219 the basic security model and the first step, or front door, into the system.
220 If you can protect system integrity in any way by *hiding* these keys, then
221 I figure it is a proactive step in the right direction.
224 ==============================================================================
225   Chapter 2 - Installing Shadow-20001016
226 ==============================================================================
228 o== Installation Commands ==o
230 I have added comments to elaborate where I feel it necessary. Comments are
231 denoted below the same as in any Bourne Shell script. A "#" at the beginning
232 of a line marks that line as a comment. I have double-spaced between related
233 command blocks for legibility and emphasis.
235 The meaning of "# Approach 1", "# Approach 2", and "# BOTH 1+2" notations is
236 detailed above in the Introduction.
238 ############################################################
239 # Approach 1
240 cd /path/to/your/sources/shadow-20001016
242 # Begin installation commands.
243 cp src/useradd.c src/useradd.c.backup &&
244 sed 's/\(.*\) (nflg || \(.*\))\(.*\)/\1\2\3/' \
245    src/useradd.c.backup > src/useradd.c &&
247 # Want md5crypt? This capability is now compiled-in by default.
248 ./configure --prefix=/usr &&
249 make &&
250 make install &&
251 cd etc &&
252 cp limits login.access /etc &&
254 # The second expression below will enable MD5-based password
255 # encoding in your /etc/login.defs file.
256 sed 's%/var/spool/mail%/var/mail%
257      s%^#MD5_CRYPT_ENAB.*no%MD5_CRYPT_ENAB yes%' login.defs.linux \
258    > /etc/login.defs &&
260 # Move some libs around and make a couple symlinks.
261 cd /lib &&
262 mv libshadow.a libshadow.la /usr/lib &&
263 ln -sf libshadow.so.0 libshadow.so &&
264 cd /usr/lib &&
265 ln -sf ../../lib/libshadow.so
267 ############################################################
268 # Approach 2
269 # If you are reading this hint after the shadow password installation
270 # and you have performed that installation by-the-lfs-book, then run
271 # these commands to turn on MD5 support.
272 cp /etc/login.defs /etc/login.defs.working &&
273 sed 's%^#MD5_CRYPT_ENAB.*no%MD5_CRYPT_ENAB yes%' /etc/login.defs.working \
274    > /etc/login.defs
276 ############################################################
277 # BOTH 1+2
278 # Make these symlinks if you want vigr . Just a nice addition.
279 cd /usr/sbin &&
280 ln -sf vipw vigr &&
281 cd /usr/share/man/man8 &&
282 ln -sf vipw.8 vigr.8
285 ==============================================================================
286   Chapter 3 - Additional Configuration/Security Steps # BOTH 1+2
287 ==============================================================================
289 o== How do I add a new user? ==o
291 Well, there is more than one way to do this of course, but we want the easiest
292 way. Right? First, please note that the relevant man pages are USERADD(8) and
293 GROUPADD(8). I mention the man pages because the following example is the
294 simplest possible way to do this. This will leave a lot to be desired, and you
295 will certainly want to refine the example to suit your needs.
297 Example: You want to add a new user "joe". He will be in group "users".
298          What to do?
300 Does group "users" already exist on your system? If not, add this new group
301 by doing:
302 /usr/sbin/groupadd users
304 Now you can add user "joe" by doing:
305 /usr/sbin/useradd -g users joe
307 Ok, now that this has been done... Can joe really use this account yet? No.
308 Why is this? Well, he doesn't have a password yet. The account is currently
309 locked. Also, by using the commands exactly as above, his home directory does
310 not yet exist on the system.
312 You can give joe a password by doing:
313 /usr/bin/passwd joe
315 That's all for now. Please refer to USERADD(8) for further info. There are a
316 great many additional options you can use. You can also create a shell script
317 to automate the procedure so that the results are always consistent. I may
318 include an example script here in time.
320 o== /etc/login.defs (configuring the shadow login suite) ==o
322 This is a very important configuration file for your system. I highly recommend
323 that you take a few moments to familiarize yourself with it. Since it has a
324 great many configuration definitions, it is almost required to know exactly
325 what is there. Besides, if you have a little time to play around with this file
326 it's actually kind of fun! ;o)
328 Before you change this file, make a backup of it for obvious reasons.
329 A good way to get an overview of this file is to simply `less /etc/login.defs'.
330 It has comments to describe what each definition does. You can also have a look
331 at LOGIN(5), `man 5 login.defs', if you need more info than these comments
332 provide.
334 In time, I will add an example /etc/login.defs file below ([3] /etc/login.defs)
335 with further information about what I believe are the best settings to use and
336 why.
338 o== Essential Permissions ==o
340 If you want to take maximum advantage of password shadowing and add some extra
341 security to your system I recommend to take the following steps. This is really
342 intended for the paranoid. In my opinion, computer security and paranoia go
343 hand-in-hand! Paranoia is good! Let me take this moment and invite you again to
344 balance these suggestions with your own needs.
347 # Restrict permissions on /bin/login and /bin/su .
348 # Refer to [1] below for explanation of why.
350 # Before restricting su to a privileged group, you must first create this
351 # group with groupadd (man 8 groupadd for details) or vigr . For example,
352 # replace "admin" below with whatever groupname you chose to use. Then, be
353 # sure to add yourself, or whoever this privileged user is, to your newly
354 # created "admin" group. Then run the following commands.
355 chmod -c 0700 /bin/login &&
356 chgrp -c admin /bin/su &&
357 chmod -c o-rx /bin/su
360 # Some other programs that should be restricted.
361 # Refer to [2] below for explanation of why.
363 # The following will remove group/other execute permissions from these programs.
364 # Since only root can effectively use any of these you might as well make them
365 # to be 0700 and be done with it. Then, privileged user can su to root and do
366 # user administration.
367 cd /usr/sbin &&
368 chmod -c go-rx chpasswd dpasswd group* grp[cu]* logoutd \
369                mkpasswd newusers pw[cu]* user* vipw
372 #== Exercise for the reader ==#
374 # Will you really use any of these programs on a daily basis? If not, you could
375 # possibly remove them from the system entirely, put them on a CD, and mount the
376 # CD when you need to do user administration. This *is* possible by the way, but
377 # you need to weigh the costs/benefits of doing so. It's up to you in the end.
381 ==============================================================================
382   Chapter 4 - Conclusion
383 ==============================================================================
385 After all of this, I assume you want to enable password shadowing... =)
387 ############################################################
388 # Approach 1
389 If you are still running within chroot on your host system and haven't booted
390 your new LFS System yet, then run:
392 /usr/sbin/pwconv
394 Then run:
396 /usr/bin/passwd root
398 ############################################################
399 # Approach 2
400 Before you run the following command, be absolutely certain that you have
401 taken a copy of your currently unshadowed password file, put it somewhere
402 safe, and chmod it to 0600 . Better safe than sorry. If something were to
403 go foul, recovery is easy. After taking the previous precautionary measure,
404 be sure you are root and are logged in on more than one console/terminal.
406 Then run:
407 /usr/sbin/pwconv
409 On the second, and/or third, terminal(s) you are logged into do some tests
410 to be certain that you get the expect results (i.e., you can login). On some
411 other terminal try logging into your normal user account. Success? Good!
412 Now, try to `su - root' . If you don't see any anomalous behaviour then you
413 should be good to go.
415 If you added passwords to your system before you changed /etc/login.defs to
416 allow MD5 support, please note that the old passwords do not get converted
417 automatically. The old password strings will still be encoded using the
418 DES-based algorithm. To change these old passwords so they will use the
419 MD5-based ciphertext format, simply run `/usr/bin/passwd <username>' for
420 each username where this is true.
422 The new encoded string will now be MD5-based. If you want to keep the original
423 password for each account run passwd twice for each one. First, change to some
424 temporary value, and then change to original.
426 ############################################################
427 # BOTH 1+2
428 Congratulations! You have done very well indeed! =)
431 ==============================================================================
432   FOOTNOTES
433 ==============================================================================
435 [1] login and su should not be world executable!
437  login:
438         As far as I have ever seen, login is only started by a getty
439         or some other root-owned process. Sometimes sshd might be setup
440         to use login. Since sshd normally runs as root, or some other
441         privileged user, this should not cause any problem.
442         No guarantee on that, can someone confirm?
444  su:
445      This program should be tightly restricted. It is suid root.
446      Security would dictate that all privileged users who might be
447      permitted to use su, should be members of a privileged group
448      whose membership consists only of trusted admins.
450      I always use wheel or admin for this, pick whatever group name
451      you want. /etc/login.defs has an avenue to restrict use of su.
452      Also, the su program itself has a config file you can opt to
453      configure: /etc/suauth .
455      This file is not created by default. `man 5 suauth' will give
456      the details on this file. In short, do look over these
457      possibilities for restricting su usage. Until then, removing
458      world execute from /bin/su is a good place to start.
461 [2] Change some other modes as an additional safeguard.
463  There are a whole slew of programs installed as part of the
464  shadow-suite into /usr/sbin . These programs should also be tightly
465  restricted to admins only. Only root can effectively use any of these
466  So, administrator does a su to root, does admin duties, and goes back
467  to his/her normal user account.
469  Note: Some of the programs do give errors if joe user is trying to
470        use one of them. If your system permissions in /etc are set
471        correctly, joe user won't be able to obtain a lock on any of
472        the relevant files in /etc/{passwd,shadow,group,gshadow} .
473        Because of this, it makes sense to simply restrict permissions
474        on these programs.
477 [3] /etc/login.defs
479  This will be added soon.