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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>Creating a user</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Linux System Administrators Guide"
HREF="index.html"><LINK
REL="UP"
TITLE="Managing user accounts"
HREF="managing-users.html"><LINK
REL="PREVIOUS"
TITLE="What's an account?"
HREF="account.html"><LINK
REL="NEXT"
TITLE="Changing user properties"
HREF="user-properties.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Linux System Administrators Guide: </TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="account.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 11. Managing user accounts</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="user-properties.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="ADDUSER"
></A
>11.2. Creating a user</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="adduser.html#MANUAL-ADDUSER"
>Section 11.2.4</A
> describes how to do it by hand.
</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="ETC-PASSWD"
></A
>11.2.1. <TT
CLASS="FILENAME"
>/etc/passwd</TT
> and other informative
files</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
>Previously this was where the user's password was stored.
</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
> Most Linux systems use <I
CLASS="GLOSSTERM"
>shadow passwords</I
>.
As mentioned, previously passwords were stored in the
<TT
CLASS="FILENAME"
>/etc/passwd</TT
> file. This newer method
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.
</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="UID-GID"
></A
>11.2.2. Picking numeric user and group ids</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 uids
(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="ETC-SKEL"
></A
>11.2.3. Initial environment: <TT
CLASS="FILENAME"
>/etc/skel</TT
></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"
></A
>11.2.4. Creating a user by hand</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. <EM
>Do not edit directly with an
editor!</EM
> <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
<TT
CLASS="OPTION"
>-R</TT
> option is most useful. The correct
permissions vary a little from one site to another, but usually
the following commands do the right thing:
<TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><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
></FONT
></TD
></TR
></TABLE
>
</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
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
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="account.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="user-properties.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>What's an account?</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="managing-users.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Changing user properties</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
|