summaryrefslogtreecommitdiff
path: root/sag-0.6.1-www/sag-0.6.1.html/x2031.html
blob: 8d4adf57334315ce1a760702da3ac4b09e2716fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
<!DOCTYPE HTML PUBLIC "-//Norman Walsh//DTD DocBook HTML 1.0//EN">
<HTML
><HEAD
><TITLE
>Creating a user</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet"><LINK
REL="HOME"
TITLE="The Linux System Administrators' Guide"
HREF="book1.html"><LINK
REL="UP"
TITLE="Managing user accounts"
HREF="c2018.html"><LINK
REL="PREVIOUS"
TITLE="Managing user accounts"
HREF="c2018.html"><LINK
REL="NEXT"
TITLE="Changing user properties"
HREF="x2124.html"></HEAD
><BODY
BGCOLOR="#FFFFFF"
TEXT="#000000"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>The Linux System Administrators' Guide</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="c2018.html"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 9. Managing user accounts</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x2124.html"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="AEN2031"
>Creating a user</A
></H1
><P
> The Linux kernel itself treats users are mere numbers.
	Each user is identified by a unique integer, the <I
CLASS="GLOSSTERM"
>user
	id</I
> or <I
CLASS="GLOSSTERM"
>uid</I
>, because numbers are
	faster and easier for a computer to process than textual names.
	A separate database outside the kernel assigns a textual name,
	the <I
CLASS="GLOSSTERM"
>username</I
>, to each user id.  The database
	contains additional information as well.  </P
><P
> To create a user, you need to add information about
	the user to the user database, and create a home directory for
	him. It may also be necessary to educate the user, and set up
	a suitable initial environment for him.  </P
><P
> Most Linux distributions come with a program for
	creating accounts. There are several such programs available.
	Two command line alternatives are <B
CLASS="COMMAND"
>adduser</B
>
	and <B
CLASS="COMMAND"
>useradd</B
>; there may be a GUI tool as well.
	Whatever the program, the result is that there is little if
	any manual work to be done. Even if the details are many and
	intricate, these programs make everything seem trivial.  However,
	<A
HREF="x2031.html#MANUAL-ADDUSER"
>the section called <I
>Creating a user by hand</I
></A
> describes how to do it by hand.
	</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN2042"
><TT
CLASS="FILENAME"
>/etc/passwd</TT
> and other informative files</A
></H2
><P
> The basic user database in a Unix system is the text file,
	<TT
CLASS="FILENAME"
>/etc/passwd</TT
> (called the <I
CLASS="GLOSSTERM"
>password
	file</I
>), which lists all valid usernames and their
	associated information. The file has one line per username,
	and is divided into seven colon-delimited fields:

	<P
></P
><UL
><LI
><P
>Username.</P
></LI
><LI
><P
>Password, in an encrypted form.</P
></LI
><LI
><P
>Numeric user id.</P
></LI
><LI
><P
>Numeric group id.</P
></LI
><LI
><P
>Full name or other description of account.</P
></LI
><LI
><P
>Home directory.</P
></LI
><LI
><P
>Login shell (program to run at login).</P
></LI
></UL
>

	The format is explained in more detail on the
	<TT
CLASS="FILENAME"
>passwd</TT
> manual page.  </P
><P
> Any user on the system may read the password file,
	so that they can, for example, learn the name of another user.
	This means that the password (the second field) is also available
	to everyone. The password file encrypts the password, so in
	theory there is no problem.  However, the encryption is breakable,
	especially if the password is weak (e.g., it is short or it can
	be found in a dictionary).  Therefore it is not a good idea to
	have the password in the password file.  </P
><P
>	Many Linux systems have <I
CLASS="GLOSSTERM"
>shadow passwords</I
>. This is
	an alternative way of storing the password: the encrypted
	password is stored in a separate file, <TT
CLASS="FILENAME"
>/etc/shadow</TT
>,
	which only root can read. The <TT
CLASS="FILENAME"
>/etc/passwd</TT
>
	file only contains a special marker in the second field.
	Any program that needs to verify a user is setuid, and
	can therefore access the shadow password file. Normal
	programs, which only use the other fields in the password
	file, can't get at the password.
	
		<A
NAME="AEN2069"
HREF="#FTN.AEN2069"
>[1]</A
>

	</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN2072"
>Picking numeric user and group ids</A
></H2
><P
> On most systems it doesn't matter what the numeric user
	and group ids are, but if you use the Network filesystem (NFS),
	you need to have the same uid and gid on all systems. This
	is because NFS also identifies users with the numeric uids.
	If you aren't using NFS, you can let your account creation tool
	pick them automatically.  </P
><P
> If you are using NFS, you'll have to be invent a mechanism
	for synchronizing account information. One alternative is to
	the NIS system (see XXX network-admin-guide).  </P
><P
> However, you should try to avoid re-using numeric uid's
	(and textual usernames), because the new owner of the uid (or
	username) may get access to the old owner's files (or mail,
	or whatever).  </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN2077"
>Initial environment: <TT
CLASS="FILENAME"
>/etc/skel</TT
></A
></H2
><P
> When the home directory for a new user is created, it is
	initialized with files from the <TT
CLASS="FILENAME"
>/etc/skel</TT
>
	directory.  The system administrator can create files in
	<TT
CLASS="FILENAME"
>/etc/skel</TT
> that will provide a nice
	default environment for users.	For example, he might create a
	<TT
CLASS="FILENAME"
>/etc/skel/.profile</TT
> that sets the EDITOR
	environment variable to some editor that is friendly towards
	new users.  </P
><P
> However, it is usually best to try to keep
	<TT
CLASS="FILENAME"
>/etc/skel</TT
> as small as possible, since it
	will be next to impossible to update existing users' files. For
	example, if the name of the friendly editor changes, all existing
	users would have to edit their <TT
CLASS="FILENAME"
>.profile</TT
>. The
	system administrator could try to do it automatically, with a
	script, but that is almost certain going to break someone's file.
	</P
><P
> Whenever possible, it is better to put global configuration
	into global files, such as <TT
CLASS="FILENAME"
>/etc/profile</TT
>. This
	way it is possible to update it without breaking users'
	own setups.  </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="MANUAL-ADDUSER"
>Creating a user by hand</A
></H2
><P
> To create a new account manually, follow these steps:


	<P
></P
><UL
><LI
><P
> Edit <TT
CLASS="FILENAME"
>/etc/passwd</TT
> with
	<B
CLASS="COMMAND"
>vipw</B
> and add a new line for the new account. Be
	careful with the syntax. <I
CLASS="EMPHASIS"
>Do not edit directly with an
	editor!</I
> <B
CLASS="COMMAND"
>vipw</B
> locks the file, so
	that other commands won't try to update it at the same time. You
	should make the password field be `<TT
CLASS="LITERAL"
>*</TT
>', so
	that it is impossible to log in.  </P
></LI
><LI
><P
> Similarly, edit <TT
CLASS="FILENAME"
>/etc/group</TT
>
	with <B
CLASS="COMMAND"
>vigr</B
>, if you need to create a new group
	as well.  </P
></LI
><LI
><P
> Create the home directory of the user with
	<B
CLASS="COMMAND"
>mkdir</B
>.  </P
></LI
><LI
><P
> Copy the files from
	<TT
CLASS="FILENAME"
>/etc/skel</TT
> to the new home directory.
	</P
></LI
><LI
><P
> Fix ownerships and permissions with
	<B
CLASS="COMMAND"
>chown</B
> and <B
CLASS="COMMAND"
>chmod</B
>. The
	<SPAN
CLASS="OPTION"
>-R</SPAN
> option is most useful.  The correct
	permissions vary a little from one site to another, but usually
	the following commands do the right thing:

<PRE
CLASS="SCREEN"
><TT
CLASS="USERINPUT"
><B
>cd /home/newusername
chown -R username.group .
chmod -R go=u,go-w .
chmod go= .</B
></TT
></PRE
>

	</P
></LI
><LI
><P
> Set the password with <B
CLASS="COMMAND"
>passwd</B
>.
	</P
></LI
></UL
>
	</P
><P
> After you set the password in the last step, the account
	will work. You shouldn't set it until everything else has been
	done, otherwise the user may inadvertently log in while you're
	still copying the files.  </P
><P
>	It is sometimes necessary to create dummy
	accounts
	
		<A
NAME="AEN2122"
HREF="#FTN.AEN2122"
>[2]</A
>
		
	that are not used by people. For example, to set up an anonymous
	FTP server (so that anyone can download files from it, without
	having to get an account first), you need to create an account
	called ftp. In such cases, it is usually not necessary to set
	the password (last step above).  Indeed, it is better not to, so
	that no-one can use the account, unless they first become root,
	since root can become any user.  </P
></DIV
></DIV
><H3
>Notes</H3
><TABLE
BORDER="0"
CLASS="FOOTNOTES"
WIDTH="100%"
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN2069"
HREF="x2031.html#AEN2069"
>[1]</A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>Yes, this means that the
		password file has all the information about a user
		<I
CLASS="EMPHASIS"
>except</I
> his password. The wonder
		of development.</P
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN2122"
HREF="x2031.html#AEN2122"
>[2]</A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>Surreal users?</P
></TD
></TR
></TABLE
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="c2018.html"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x2124.html"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Managing user accounts</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c2018.html"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Changing user properties</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>