(no commit message)
[ikiwiki.git] / docs / handbook / handbook-users-modifying.mdwn
1
2
3
4 ## 8.6 Modifying Accounts 
5
6
7
8 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.
9
10
11
12 [[!table  data="""
13 | Command | Summary 
14  [adduser(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=adduser&section=8) | The recommended command-line application for adding new users. 
15  [rmuser(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rmuser&section=8) | The recommended command-line application for removing users. 
16  [chpass(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chpass&section=1) | A flexible tool to change user database information. 
17  [passwd(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=passwd&section=1) | The simple command-line tool to change user passwords. 
18  [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. |
19
20 """]]
21
22 ### 8.6.1 adduser 
23
24
25
26 [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.
27
28
29
30 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.
31
32
33
34  **Example 8-1. Configuring `adduser` and adding a user** 
35
36
37
38     
39
40     # adduser -v
41
42     Use option -silent if you don't want to see all warnings and questions.
43
44     Check /etc/shells
45
46     Check /etc/master.passwd
47
48     Check /etc/group
49
50     Enter your default shell: csh date no sh tcsh zsh [sh]: zsh
51
52     Your default shell is: zsh -> /usr/local/bin/zsh
53
54     Enter your default HOME partition: [/home]:
55
56     Copy dotfiles from: /usr/share/skel no [/usr/share/skel]:
57
58     Send message from file: /etc/adduser.message no
59
60     [/etc/adduser.message]: no
61
62     Do not send message
63
64     Use passwords (y/n) [y]: y
65
66     
67
68     Write your changes to /etc/adduser.conf? (y/n) [n]: y
69
70     
71
72     Ok, let's go.
73
74     Don't worry about mistakes. I will give you the chance later to correct any input.
75
76     Enter username [a-z0-9_-]: jru
77
78     Enter full name []: J. Random User
79
80     Enter shell csh date no sh tcsh zsh [zsh]:
81
82     Enter home directory (full path) [/home/jru]:
83
84     Uid [1001]:
85
86     Enter login class: default []:
87
88     Login group jru [jru]:
89
90     Login group is ***jru***. Invite jru into other groups: guest no
91
92     [no]: wheel
93
94     Enter password []:
95
96     Enter password again []:
97
98     
99
100     Name:         jru
101
102     Password: ****
103
104     Fullname: J. Random User
105
106     Uid:          1001
107
108     Gid:          1001 (jru)
109
110     Class:
111
112     Groups:       jru wheel
113
114     HOME:     /home/jru
115
116     Shell:        /usr/local/bin/zsh
117
118     OK? (y/n) [y]: y
119
120     Added user ***jru***
121
122     Copy files from /usr/share/skel to /home/jru
123
124     Add another user? (y/n) [y]: n
125
126     Goodbye!
127
128     #
129
130
131
132
133
134 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.)
135
136
137
138  **Note:** The password you type in is not echoed, nor are asterisks displayed. Make sure you do not mistype the password twice.
139
140
141
142  **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.
143
144
145
146 ### 8.6.2 rmuser 
147
148
149
150 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:
151
152
153
154   1. Removes the user's [crontab(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=crontab&section=1) entry (if any).
155
156   1. Removes any [at(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=at&section=1) jobs belonging to the user.
157
158   1. Kills all processes owned by the user.
159
160   1. Removes the user from the system's local password file.
161
162   1. Removes the user's home directory (if it is owned by the user).
163
164   1. Removes the incoming mail files belonging to the user from `/var/mail`.
165
166   1. Removes all files owned by the user from temporary file storage areas such as `/tmp`.
167
168   1. Finally, removes the username from all groups to which it belongs in `/etc/group`.
169
170    **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).
171
172
173
174 [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.
175
176
177
178 By default, an interactive mode is used, which attempts to make sure you know what you are doing.
179
180
181
182  **Example 8-2. `rmuser` Interactive Account Removal** 
183
184
185
186     
187
188     # rmuser jru
189
190     Matching password entry:
191
192     jru:*:1001:1001::0:0:J. Random User:/home/jru:/usr/local/bin/zsh
193
194     Is this the entry you wish to remove? y
195
196     Remove user's home directory (/home/jru)? y
197
198     Updating password file, updating databases, done.
199
200     Updating group file: trusted (removing group jru -- personal group is empty) done.
201
202     Removing user's incoming mail file /var/mail/jru: done.
203
204     Removing files belonging to jru from /tmp: done.
205
206     Removing files belonging to jru from /var/tmp: done.
207
208     Removing files belonging to jru from /var/tmp/vi.recover: done.
209
210     #
211
212
213
214
215
216 ### 8.6.3 chpass 
217
218
219
220 [chpass(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chpass&section=1) changes user database information such as passwords, shells, and personal information.
221
222
223
224 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).
225
226
227
228 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.
229
230
231
232 ***'Example 8-3. Interactive `chpass` by Superuser***'
233
234
235
236     
237
238     #Changing user database information for jru.
239
240     Login: jru
241
242     Password: *
243
244     Uid [#]: 1001
245
246     Gid [# or name]: 1001
247
248     Change [month day year]:
249
250     Expire [month day year]:
251
252     Class:
253
254     Home directory: /home/jru
255
256     Shell: /usr/local/bin/zsh
257
258     Full Name: J. Random User
259
260     Office Location:
261
262     Office Phone:
263
264     Home Phone:
265
266     Other information:
267
268
269
270
271
272 The normal user can change only a small subset of this information, and only for themselves.
273
274
275
276  **Example 8-4. Interactive chpass by Normal User** 
277
278
279
280     
281
282     #Changing user database information for jru.
283
284     Shell: /usr/local/bin/zsh
285
286     Full Name: J. Random User
287
288     Office Location:
289
290     Office Phone:
291
292     Home Phone:
293
294     Other information:
295
296
297
298
299
300  **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].
301
302
303
304 ### 8.6.4 passwd 
305
306
307
308 [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.
309
310
311
312  **Note:** To prevent accidental or unauthorized changes, the original password must be entered before a new password can be set.
313
314
315
316  **Example 8-5. Changing Your Password** 
317
318
319
320     
321
322     % passwd
323
324     Changing local password for jru.
325
326     Old password:
327
328     New password:
329
330     Retype new password:
331
332     passwd: updating the database...
333
334     passwd: done
335
336
337
338
339
340 ***'Example 8-6. Changing Another User's Password as the Superuser***'
341
342
343
344     
345
346     # passwd jru
347
348     Changing local password for jru.
349
350     New password:
351
352     Retype new password:
353
354     passwd: updating the database...
355
356     passwd: done
357
358
359
360
361
362  **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.
363
364
365
366 ### 8.6.5 pw 
367
368
369
370 [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.
371
372
373
374 #### Notes 
375
376
377
378 [[!table  data="""
379 |<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. |
380
381 """]]
382
383
384
385
386
387 CategoryHandbook
388
389 CategoryHandbook-usermanagement
390