(no commit message)
[ikiwiki.git] / docs / newhandbook / Users / index.mdwn
1 # Users and Basic Account Management 
2
3 ***Contributed by Neil Blakey-Milner. ***
4
5 [[!toc  levels=3]]
6
7
8 ## Synopsis 
9
10
11
12 DragonFly allows multiple users to use the computer at the same time. Obviously, only one of those users can be sitting in front of the screen and keyboard at any one time [(1)](#FTN.AEN6502), but any number of users can log in through the network to get their work done. To use the system every user must have an account.
13
14
15 After reading this chapter, you will know:
16
17
18 * The differences between the various user accounts on a DragonFly system.
19
20
21 * How to add user accounts.
22
23
24 * How to remove user accounts.
25
26
27 * How to change account details, such as the user's full name, or preferred shell.
28
29
30 * How to set limits on a per-account basis, to control the resources such as memory and CPU time that accounts and groups of accounts are allowed to access.
31
32
33 * How to use groups to make account management easier.
34
35
36
37 Before reading this chapter, you should:
38
39
40
41
42 * Understand the basics of UNIX® and DragonFly ([Chapter 3](basics.html)).
43
44
45
46 #### Notes 
47
48
49
50 [[!table  data="""
51 <tablestyle="width:100%"> [ (1)](users.html#AEN6502) | Well, unless you hook up multiple terminals, but we will save that for [ Chapter 17](serialcomms.html).
52  | |
53
54 """]]
55
56
57
58
59
60 CategoryHandbook
61
62 Category
63
64
65
66
67
68
69 ## Introduction 
70
71
72
73 All access to the system is achieved via accounts, and all processes are run by users, so user and account management are of integral importance on DragonFly systems.
74
75
76
77 Every account on a DragonFly system has certain information associated with it to identify the account.
78
79
80
81 * User name: The user name as it would be typed at the login: prompt. User names must be unique across the computer; you may not have two users with the same user name. There are a number of rules for creating valid user names, documented in [passwd(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=passwd&section=5); you would typically use user names that consist of eight or fewer all lower case characters.Password:: Each account has a password associated with it. The password may be blank, in which case no password will be required to access the system. This is normally a very bad idea; every account should have a password.
82
83 * User ID (UID): The UID is a number, traditionally from 0 to 65535[(1)](#FTN.USERS-LARGEUIDGID), used to uniquely identify the user to the system. Internally, DragonFly uses the UID to identify users--any DragonFly commands that allow you to specify a user name will convert it to the UID before working with it. This means that you can have several accounts with different user names but the same UID. As far as DragonFly is concerned, these accounts are one user. It is unlikely you will ever need to do this.
84
85 * Group ID (GID): The GID is a number, traditionally from 0 to 65535[users-introduction.html#FTN.USERS-LARGEUIDGID (1)], used to uniquely identify the primary group that the user belongs to. Groups are a mechanism for controlling access to resources based on a user's GID rather than their UID. This can significantly reduce the size of some configuration files. A user may also be in more than one group.
86
87 * Login class: Login classes are an extension to the group mechanism that provide additional flexibility when tailoring the system to different users.
88
89 * Password change time: By default DragonFly does not force users to change their passwords periodically. You can enforce this on a per-user basis, forcing some or all of your users to change their passwords after a certain amount of time has elapsed.
90
91 * Account expiry time: By default DragonFly does not expire accounts. If you are creating accounts that you know have a limited lifespan, for example, in a school where you have accounts for the students, then you can specify when the account expires. After the expiry time has elapsed the account cannot be used to log in to the system, although the account's directories and files will remain.
92
93 * User's full name: The user name uniquely identifies the account to DragonFly, but does not necessarily reflect the user's real name. This information can be associated with the account.
94
95 * Home directory: The home directory is the full path to a directory on the system in which the user will start when logging on to the system. A common convention is to put all user home directories under `/home/`***username***. The user would store their personal files in their home directory, and any directories they may create in there.
96
97 * User shell: The shell provides the default environment users use to interact with the system. There are many different kinds of shells, and experienced users will have their own preferences, which can be reflected in their account settings.
98
99
100
101 There are three main types of accounts: the [users-superuser.html Superuser], [users-system.html system users], and [users-user.html user accounts]. The Superuser account, usually called `root`, is used to manage the system with no limitations on privileges. System users run services. Finally, user accounts are used by real people, who log on, read mail, and so forth.
102
103
104
105 #### Notes 
106
107
108
109 [[!table  data="""
110 <tablestyle="width:100%"> [users-introduction.html#USERS-LARGEUIDGID (1)] | It is possible to use UID/GIDs as large as 4294967295, but such IDs can cause serious problems with software that makes assumptions about the values of IDs. |
111  | | 
112 """]]
113
114
115
116
117
118
119
120 ## The Superuser Account 
121
122
123
124 The superuser account, usually called `root`, comes preconfigured to facilitate system administration, and should not be used for day-to-day tasks like sending and receiving mail, general exploration of the system, or programming.
125
126
127
128 This is because the superuser, unlike normal user accounts, can operate without limits, and misuse of the superuser account may result in spectacular disasters. User accounts are unable to destroy the system by mistake, so it is generally best to use normal user accounts whenever possible, unless you especially need the extra privilege.
129
130
131
132 You should always double and triple-check commands you issue as the superuser, since an extra space or missing character can mean irreparable data loss.
133
134
135
136 So, the first thing you should do after reading this chapter is to create an unprivileged user account for yourself for general usage if you have not already. This applies equally whether you are running a multi-user or single-user machine. Later in this chapter, we discuss how to create additional accounts, and how to change between the normal user and superuser.
137
138
139
140
141
142
143
144 ## System Accounts 
145
146
147
148 System users are those used to run services such as DNS, mail, web servers, and so forth. The reason for this is security; if all services ran as the superuser, they could act without restriction.
149
150
151
152 Examples of system users are `daemon`, `operator`, `bind` (for the Domain Name Service), and `news`. Often sysadmins create `httpd` to run web servers they install.
153
154
155
156 `nobody` is the generic unprivileged system user. However, it is important to keep in mind that the more services that use `nobody`, the more files and processes that user will become associated with, and hence the more privileged that user becomes.
157
158
159
160
161
162
163
164
165
166
167
168 ## User Accounts 
169
170
171
172 User accounts are the primary means of access for real people to the system, and these accounts insulate the user and the environment, preventing the users from damaging the system or other users, and allowing users to customize their environment without affecting others.
173
174
175
176 Every person accessing your system should have a unique user account. This allows you to find out who is doing what, prevent people from clobbering each others' settings or reading each others' mail, and so forth.
177
178
179
180 Each user can set up their own environment to accommodate their use of the system, by using alternate shells, editors, key bindings, and language.
181
182
183
184
185
186
187
188 ## Modifying Accounts 
189
190
191
192 There are a variety of different commands available in the UNIX® environment to manipulate user accounts. The most common commands are summarized below, followed by more detailed examples of their usage.
193
194
195
196 [[!table  data="""
197 Command | Summary 
198  [adduser(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=adduser&section=8) | The recommended command-line application for adding new users. 
199  [rmuser(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rmuser&section=8) | The recommended command-line application for removing users. 
200  [chpass(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chpass&section=1) | A flexible tool to change user database information. 
201  [passwd(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=passwd&section=1) | The simple command-line tool to change user passwords. 
202  [pw(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=pw&section=8) | A powerful and flexible tool to modify all aspects of user accounts. |
203
204 """]]
205
206 ### adduser 
207
208
209
210 [adduser(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=adduser&section=8) is a simple program for adding new users. It creates entries in the system `passwd` and `group` files. It will also create a home directory for the new user, copy in the default configuration files (***dotfiles***) from `/usr/share/skel`, and can optionally mail the new user a welcome message.
211
212
213
214 To create the initial configuration file, use `adduser -s -config_create`. [(1)](#FTN.AEN6699) Next, we configure [adduser(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=adduser&section=8) defaults, and create our first user account, since using `root` for normal usage is evil and nasty.
215
216
217
218  **Example 8-1. Configuring `adduser` and adding a user** 
219
220    
221
222     # adduser -v
223
224     Use option -silent if you don't want to see all warnings and questions.
225
226     Check /etc/shells
227
228     Check /etc/master.passwd
229
230     Check /etc/group
231
232     Enter your default shell: csh date no sh tcsh zsh [sh]: zsh
233
234     Your default shell is: zsh -&gt; /usr/local/bin/zsh
235
236     Enter your default HOME partition: [/home]:
237
238     Copy dotfiles from: /usr/share/skel no [/usr/share/skel]:
239
240     Send message from file: /etc/adduser.message no
241
242     [/etc/adduser.message]: no
243
244     Do not send message
245
246     Use passwords (y/n) [y]: y
247
248     
249
250     Write your changes to /etc/adduser.conf? (y/n) [n]: y
251
252     
253
254     Ok, let's go.
255
256     Don't worry about mistakes. I will give you the chance later to correct any input.
257
258     Enter username [a-z0-9_-]: jru
259
260     Enter full name []: J. Random User
261
262     Enter shell csh date no sh tcsh zsh [zsh]:
263
264     Enter home directory (full path) [/home/jru]:
265
266     Uid [1001]:
267
268     Enter login class: default []:
269
270     Login group jru [jru]:
271
272     Login group is ***jru***. Invite jru into other groups: guest no
273
274     [no]: wheel
275
276     Enter password []:
277
278     Enter password again []:
279
280     
281
282     Name:         jru
283
284     Password: ****
285
286     Fullname: J. Random User
287
288     Uid:          1001
289
290     Gid:          1001 (jru)
291
292     Class:
293
294     Groups:       jru wheel
295
296     HOME:     /home/jru
297
298     Shell:        /usr/local/bin/zsh
299
300     OK? (y/n) [y]: y
301
302     Added user ***jru***
303
304     Copy files from /usr/share/skel to /home/jru
305
306     Add another user? (y/n) [y]: n
307
308     Goodbye!
309
310     #
311
312
313
314 In summary, we changed the default shell to  **zsh**  (an additional shell found in pkgsrc®), and turned off the sending of a welcome mail to added users. We then saved the configuration, created an account for `jru`, and made sure `jru` is in `wheel` group (so that she may assume the role of `root` with the [su(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=su&section=1) command.)
315
316
317  **Note:** The password you type in is not echoed, nor are asterisks displayed. Make sure you do not mistype the password twice.
318
319
320  **Note:** Just use [adduser(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=adduser&section=8) without arguments from now on, and you will not have to go through changing the defaults. If the program asks you to change the defaults, exit the program, and try the `-s` option.
321
322
323
324 ### rmuser 
325
326
327
328 You can use [rmuser(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rmuser&section=8) to completely remove a user from the system. [rmuser(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rmuser&section=8) performs the following steps:
329
330
331
332   1. Removes the user's [crontab(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=crontab&section=1) entry (if any).
333
334   1. Removes any [at(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=at&section=1) jobs belonging to the user.
335
336   1. Kills all processes owned by the user.
337
338   1. Removes the user from the system's local password file.
339
340   1. Removes the user's home directory (if it is owned by the user).
341
342   1. Removes the incoming mail files belonging to the user from `/var/mail`.
343
344   1. Removes all files owned by the user from temporary file storage areas such as `/tmp`.
345
346   1. Finally, removes the username from all groups to which it belongs in `/etc/group`.
347
348    **Note:** If a group becomes empty and the group name is the same as the username, the group is removed; this complements the per-user unique groups created by [adduser(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=adduser&section=8).
349
350
351
352 [rmuser(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rmuser&section=8) cannot be used to remove superuser accounts, since that is almost always an indication of massive destruction.
353
354
355
356 By default, an interactive mode is used, which attempts to make sure you know what you are doing.
357
358
359
360  **Example 8-2. `rmuser` Interactive Account Removal** 
361
362
363
364     
365
366     # rmuser jru
367
368     Matching password entry:
369
370     jru:*:1001:1001::0:0:J. Random User:/home/jru:/usr/local/bin/zsh
371
372     Is this the entry you wish to remove? y
373
374     Remove user's home directory (/home/jru)? y
375
376     Updating password file, updating databases, done.
377
378     Updating group file: trusted (removing group jru -- personal group is empty) done.
379
380     Removing user's incoming mail file /var/mail/jru: done.
381
382     Removing files belonging to jru from /tmp: done.
383
384     Removing files belonging to jru from /var/tmp: done.
385
386     Removing files belonging to jru from /var/tmp/vi.recover: done.
387
388     #
389
390
391
392
393
394 ### chpass 
395
396
397
398 [chpass(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chpass&section=1) changes user database information such as passwords, shells, and personal information.
399
400
401 Only system administrators, as the superuser, may change other users' information and passwords with [chpass(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chpass&section=1).
402
403
404 When passed no options, aside from an optional username, [chpass(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chpass&section=1) displays an editor containing user information. When the user exists from the editor, the user database is updated with the new information.
405
406
407
408 ***'Example 8-3. Interactive `chpass` by Superuser***'
409
410
411
412     
413
414     #Changing user database information for jru.
415
416     Login: jru
417
418     Password: *
419
420     Uid [#]: 1001
421
422     Gid [# or name]: 1001
423
424     Change [month day year]:
425
426     Expire [month day year]:
427
428     Class:
429
430     Home directory: /home/jru
431
432     Shell: /usr/local/bin/zsh
433
434     Full Name: J. Random User
435
436     Office Location:
437
438     Office Phone:
439
440     Home Phone:
441
442     Other information:
443
444
445
446
447
448 The normal user can change only a small subset of this information, and only for themselves.
449
450
451
452  **Example 8-4. Interactive chpass by Normal User** 
453
454     
455
456     #Changing user database information for jru.
457
458     Shell: /usr/local/bin/zsh
459
460     Full Name: J. Random User
461
462     Office Location:
463
464     Office Phone:
465
466     Home Phone:
467
468     Other information:
469
470
471
472
473
474  **Note:** [chfn(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chfn&section=1) and [chsh(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chsh&section=1) are just links to [chpass(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chpass&section=1), as are [ypchpass(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ypchpass&section=1), [ypchfn(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ypchfn&section=1), and [ypchsh(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ypchsh&section=1). NIS support is automatic, so specifying the `yp` before the command is not necessary. If this is confusing to you, do not worry, NIS will be covered in [advanced-networking.html Chapter 19].
475
476
477
478 ### passwd 
479
480
481
482 [passwd(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=passwd&section=1) is the usual way to change your own password as a user, or another user's password as the superuser.
483
484
485
486  **Note:** To prevent accidental or unauthorized changes, the original password must be entered before a new password can be set.
487
488
489
490  **Example 8-5. Changing Your Password** 
491
492
493
494     
495
496     % passwd
497
498     Changing local password for jru.
499
500     Old password:
501
502     New password:
503
504     Retype new password:
505
506     passwd: updating the database...
507
508     passwd: done
509
510
511
512
513
514 ***'Example 8-6. Changing Another User's Password as the Superuser***'
515
516
517
518     
519
520     # passwd jru
521
522     Changing local password for jru.
523
524     New password:
525
526     Retype new password:
527
528     passwd: updating the database...
529
530     passwd: done
531
532
533
534
535
536  **Note:** As with [chpass(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chpass&section=1), [yppasswd(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=yppasswd&section=1) is just a link to [passwd(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=passwd&section=1), so NIS works with either command.
537
538
539
540 ### pw 
541
542
543
544 [pw(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=pw&section=8) is a command line utility to create, remove, modify, and display users and groups. It functions as a front end to the system user and group files. [pw(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=pw&section=8) has a very powerful set of command line options that make it suitable for use in shell scripts, but new users may find it more complicated than the other commands presented here.
545
546
547
548 #### Notes 
549
550
551
552 [[!table  data="""
553 <tablestyle#"width:100%"> [(1)](users-modifying.html#AEN6699) | The `-s` makes [adduser(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=adduser&section=8) default to quiet. We use `-v` later when we want to change defaults. |
554 | | 
555 """]]
556
557
558
559
560
561 CategoryHandbook
562
563 CategoryHandbook-usermanagement
564
565
566
567
568
569
570
571 ## Limiting Users 
572
573 <!-- XXX: check this section, I got the feeling there might be something outdated in it. I'm not familiar with it -->
574
575 If you have users, the ability to limit their system use may have come to mind. DragonFly provides several ways an administrator can limit the amount of system resources an individual may use. These limits are divided into two sections: disk quotas, and other resource limits.
576
577
578
579 Disk quotas limit disk usage to users, and they provide a way to quickly check that usage without calculating it every time. Quotas are discussed in [quotas.html Section 12.12].
580
581
582
583 The other resource limits include ways to limit the amount of CPU, memory, and other resources a user may consume. These are defined using login classes and are discussed here.
584
585
586
587 Login classes are defined in `/etc/login.conf`. The precise semantics are beyond the scope of this section, but are described in detail in the [login.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=login.conf&section=5) manual page. It is sufficient to say that each user is assigned to a login class (`default` by default), and that each login class has a set of login capabilities associated with it. A login capability is a `name=value` pair, where `name` is a well-known identifier and `value` is an arbitrary string processed accordingly depending on the name. Setting up login classes and capabilities is rather straight-forward and is also described in [login.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=login.conf&section=5).
588
589
590
591 Resource limits are different from plain vanilla login capabilities in two ways. First, for every limit, there is a soft (current) and hard limit. A soft limit may be adjusted by the user or application, but may be no higher than the hard limit. The latter may be lowered by the user, but never raised. Second, most resource limits apply per process to a specific user, not the user as a whole. Note, however, that these differences are mandated by the specific handling of the limits, not by the implementation of the login capability framework (i.e., they are not ***really*** a special case of login capabilities).
592
593
594
595 And so, without further ado, below are the most commonly used resource limits (the rest, along with all the other login capabilities, may be found in [login.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=login.conf&section=5)).
596
597
598
599
600 * `coredumpsize`: The limit on the size of a core file generated by a program is, for obvious reasons, subordinate to other limits on disk usage (e.g., `filesize`, or disk quotas). Nevertheless, it is often used as a less-severe method of controlling disk space consumption: since users do not generate core files themselves, and often do not delete them, setting this may save them from running out of disk space should a large program (e.g.,  **emacs** ) crash.
601
602
603 * `cputime`: This is the maximum amount of CPU time a user's process may consume. Offending processes will be killed by the kernel.
604
605  **Note:** This is a limit on CPU ***time*** consumed, not percentage of the CPU as displayed in some fields by [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top&section=1) and [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section=1). A limit on the latter is, at the time of this writing, not possible, and would be rather useless: legitimate use of a compiler, for instance, can easily use almost 100% of a CPU for some time.
606
607
608 * `filesize`: This is the maximum size of a file the user may possess. Unlike [quotas.html disk quotas], this limit is enforced on individual files, not the set of all files a user owns.
609
610
611 * `maxproc`: This is the maximum number of processes a user may be running. This includes foreground and background processes alike. For obvious reasons, this may not be larger than the system limit specified by the `kern.maxproc` [sysctl(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sysctl&section=8). Also note that setting this too small may hinder a user's productivity: it is often useful to be logged in multiple times or execute pipelines. Some tasks, such as compiling a large program, also spawn multiple processes (e.g., [make(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=make&section=1), [cc(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=cc&section=1), and other intermediate preprocessors).
612
613
614 * `memorylocked`: This is the maximum amount a memory a process may have requested to be locked into main memory (e.g., see [mlock(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=mlock&section2)). Some system-critical programs, such as [amd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=amd&section=8), lock into main memory such that in the event of being swapped out, they do not contribute to a system's trashing in time of trouble.
615
616
617 * `memoryuse`: This is the maximum amount of memory a process may consume at any given time. It includes both core memory and swap usage. This is not a catch-all limit for restricting memory consumption, but it is a good start.
618
619
620 * `openfiles`: This is the maximum amount of files a process may have open. In DragonFly, files are also used to represent sockets and IPC channels; thus, be careful not to set this too low. The system-wide limit for this is defined by the `kern.maxfiles` [sysctl(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sysctl&section=8).
621
622
623 * `sbsize`: This is the limit on the amount of network memory, and thus mbufs, a user may consume. This originated as a response to an old DoS attack by creating a lot of sockets, but can be generally used to limit network communications.
624
625
626 * `stacksize`: This is the maximum size a process' stack may grow to. This alone is not sufficient to limit the amount of memory a program may use; consequently, it should be used in conjunction with other limits.
627
628
629
630 There are a few other things to remember when setting resource limits. Following are some general tips, suggestions, and miscellaneous comments.
631
632
633
634
635 * Processes started at system startup by `/etc/rc` are assigned to the `daemon` login class.
636
637
638 * Although the `/etc/login.conf` that comes with the system is a good source of reasonable values for most limits, only you, the administrator, can know what is appropriate for your system. Setting a limit too high may open your system up to abuse, while setting it too low may put a strain on productivity.
639
640
641 * Users of the X Window System (X11) should probably be granted more resources than other users. X11 by itself takes a lot of resources, but it also encourages users to run more programs simultaneously.
642
643
644 * Remember that many limits apply to individual processes, not the user as a whole. For example, setting `openfiles` to 50 means that each process the user runs may open up to 50 files. Thus, the gross amount of files a user may open is the value of `openfiles` multiplied by the value of `maxproc`. This also applies to memory consumption.
645
646
647
648 For further information on resource limits and login classes and capabilities in general, please consult the relevant manual pages: [cap_mkdb(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#cap_mkdb&section1), [getrlimit(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=getrlimit&section=2), [login.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=login.conf&section=5).
649
650
651
652
653
654
655
656
657 ## Personalizing Users 
658
659
660
661 Localization is an environment set up by the system administrator or user to accommodate different languages, character sets, date and time standards, and so on. This is discussed in [this chapter](l10n.html).
662
663
664
665 ## Groups 
666
667
668
669 A group is simply a list of users. Groups are identified by their group name and GID (Group ID). In DragonFly (and most other UNIX® like systems), the two factors the kernel uses to decide whether a process is allowed to do something is its user ID and list of groups it belongs to. Unlike a user ID, a process has a list of groups associated with it. You may hear some things refer to the ***group ID*** of a user or process; most of the time, this just means the first group in the list.
670
671
672
673 The group name to group ID map is in `/etc/group`. This is a plain text file with four colon-delimited fields. The first field is the group name, the second is the encrypted password, the third the group ID, and the fourth the comma-delimited list of members. It can safely be edited by hand (assuming, of course, that you do not make any syntax errors!). For a more complete description of the syntax, see the [group(5)](http://leaf.dragonflybsd.org/cgi/web-man?command#group&section5) manual page.
674
675
676
677 If you do not want to edit `/etc/group` manually, you can use the [pw(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#pw&section8) command to add and edit groups. For example, to add a group called `teamtwo` and then confirm that it exists you can use:
678
679
680
681  **Example 8-7. Adding a Group Using pw(8)** 
682
683
684
685     
686
687     # pw groupadd teamtwo
688
689     # pw groupshow teamtwo
690
691     teamtwo:*:1100:
692
693
694
695
696
697 The number `1100` above is the group ID of the group `teamtwo`. Right now, `teamtwo` has no members, and is thus rather useless. Let's change that by inviting `jru` to the `teamtwo` group.
698
699
700
701  **Example 8-8. Adding Somebody to a Group Using pw(8)** 
702
703
704
705     
706
707     # pw groupmod teamtwo -M jru
708
709     # pw groupshow teamtwo
710
711     teamtwo:*:1100:jru
712
713
714
715
716
717 The argument to the `-M` option is a comma-delimited list of users who are members of the group. From the preceding sections, we know that the password file also contains a group for each user. The latter (the user) is automatically added to the group list by the system; the user will not show up as a member when using the `groupshow` command to [pw(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#pw&section8), but will show up when the information is queried via [id(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=id&section=1) or similar tool. In other words, [pw(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=pw&section=8) only manipulates the `/etc/group` file; it will never attempt to read additionally data from `/etc/passwd`.
718
719
720
721  **Example 8-9. Using id(1) to Determine Group Membership** 
722
723
724
725     
726
727     % id jru
728
729     uid#1001(jru) gid1001(jru) groups=1001(jru), 1100(teamtwo)
730
731
732
733
734
735 As you can see, `jru` is a member of the groups `jru` and `teamtwo`.
736
737
738
739 For more information about [pw(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#pw&section8), see its manual page, and for more information on the format of `/etc/group`, consult the [group(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=group&section=5) manual page.
740
741
742
743