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 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
|
<!-- vim: set sw=2 et sts=2 ft=xml: -->
<!-- Last content review: 2024-01-21T07:35:56 UTC -->
<chapter id="_authentication">
<title>Authentication and access controls</title>
<para>When a person (or a program) requests access to the system, authentication confirms the identity to be a trusted one.</para>
<warning>
<para>Configuration errors of PAM may lock you out of your own system. You must have a rescue CD handy or setup an alternative boot partition. To recover, boot the system with them and correct things from there.</para>
</warning>
<section id="_normal_unix_authentication">
<title>Normal Unix authentication</title>
<para>Normal Unix authentication is provided by the <literal>pam_unix</literal>(8) module under the <ulink url="https://en.wikipedia.org/wiki/Pluggable_Authentication_Modules">PAM (Pluggable Authentication Modules)</ulink>. Its 3 important configuration files, with "<literal>:</literal>" separated entries, are the following.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>3 important configuration files for <literal>pam_unix</literal>(8)</title>
<tgroup cols="5">
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="38pt" align="left"/>
<colspec colwidth="48pt" align="left"/>
<colspec colwidth="228pt" align="left"/>
<thead>
<row>
<entry> file </entry>
<entry> permission </entry>
<entry> user </entry>
<entry> group </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>/etc/passwd</literal> </entry>
<entry> <literal>-rw-r--r--</literal> </entry>
<entry> <literal>root</literal> </entry>
<entry> <literal>root</literal> </entry>
<entry> (sanitized) user account information </entry>
</row>
<row>
<entry> <literal>/etc/shadow</literal> </entry>
<entry> <literal>-rw-r-----</literal> </entry>
<entry> <literal>root</literal> </entry>
<entry> <literal>shadow</literal> </entry>
<entry> secure user account information </entry>
</row>
<row>
<entry> <literal>/etc/group</literal> </entry>
<entry> <literal>-rw-r--r--</literal> </entry>
<entry> <literal>root</literal> </entry>
<entry> <literal>root</literal> </entry>
<entry> group information </entry>
</row>
</tbody>
</tgroup>
</table>
<para>"<literal>/etc/passwd</literal>" contains the following.</para>
<screen> ...
user1:x:1000:1000:User1 Name,,,:/home/user1:/bin/bash
user2:x:1001:1001:User2 Name,,,:/home/user2:/bin/bash
...</screen>
<para>As explained in <literal>passwd</literal>(5), each "<literal>:</literal>" separated entry of this file means the following.</para>
<itemizedlist>
<listitem> <para> Login name </para> </listitem>
<listitem> <para> Password specification entry </para> </listitem>
<listitem> <para> Numerical user ID </para> </listitem>
<listitem> <para> Numerical group ID </para> </listitem>
<listitem> <para> User name or comment field </para> </listitem>
<listitem> <para> User home directory </para> </listitem>
<listitem> <para> Optional user command interpreter </para> </listitem>
</itemizedlist>
<para>The second entry of "<literal>/etc/passwd</literal>" was used for the encrypted password entry. After the introduction of "<literal>/etc/shadow</literal>", this entry is used for the password specification entry.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>The second entry content of "<literal>/etc/passwd</literal>"</title>
<tgroup cols="2">
<colspec colwidth="43pt" align="left"/>
<colspec colwidth="244pt" align="left"/>
<thead>
<row>
<entry> content </entry>
<entry> meaning </entry>
</row>
</thead>
<tbody>
<row>
<entry> (empty) </entry>
<entry> passwordless account </entry>
</row>
<row>
<entry> x </entry>
<entry> the encrypted password is in "<literal>/etc/shadow</literal>" </entry>
</row>
</tbody>
</tgroup>
</table>
<para>"<literal>/etc/shadow</literal>" contains the following.</para>
<screen> ...
user1:$1$Xop0FYH9$IfxyQwBe9b8tiyIkt2P4F/:13262:0:99999:7:::
user2:$1$vXGZLVbS$ElyErNf/agUDsm1DehJMS/:13261:0:99999:7:::
...</screen>
<para>As explained in <literal>shadow</literal>(5), each "<literal>:</literal>" separated entry of this file means the following.</para>
<itemizedlist>
<listitem> <para> Login name </para> </listitem>
<listitem> <para> Encrypted password (The initial "<literal>$1$</literal>" indicates use of the MD5 encryption. The "*" indicates no login.) </para> </listitem>
<listitem> <para> Date of the last password change, expressed as the number of days since Jan 1, 1970 </para> </listitem>
<listitem> <para> Number of days the user will have to wait before she will be allowed to change her password again </para> </listitem>
<listitem> <para> Number of days after which the user will have to change her password </para> </listitem>
<listitem> <para> Number of days before a password is going to expire during which the user should be warned </para> </listitem>
<listitem> <para> Number of days after a password has expired during which the password should still be accepted </para> </listitem>
<listitem> <para> Date of expiration of the account, expressed as the number of days since Jan 1, 1970 </para> </listitem>
<listitem> <para> … </para> </listitem>
</itemizedlist>
<para>"<literal>/etc/group</literal>" contains the following.</para>
<screen>group1:x:20:user1,user2</screen>
<para>As explained in <literal>group</literal>(5), each "<literal>:</literal>" separated entry of this file means the following.</para>
<itemizedlist>
<listitem> <para> Group name </para> </listitem>
<listitem> <para> Encrypted password (not really used) </para> </listitem>
<listitem> <para> Numerical group ID </para> </listitem>
<listitem> <para> "," separated list of user names </para> </listitem>
</itemizedlist>
<note> <para>"<literal>/etc/gshadow</literal>" provides the similar function as "<literal>/etc/shadow</literal>" for "<literal>/etc/group</literal>" but is not really used.</para> </note>
<note> <para>The actual group membership of a user may be dynamically added if "<literal>auth optional pam_group.so</literal>" line is added to "<literal>/etc/pam.d/common-auth</literal>" and set it in "<literal>/etc/security/group.conf</literal>". See <literal>pam_group</literal>(8).</para> </note>
<note> <para>The <literal>base-passwd</literal> package contains an authoritative list of the user and the group: "<literal>/usr/share/doc/base-passwd/users-and-groups.html</literal>".</para> </note>
</section>
<section id="_managing_account_and_password_information">
<title>Managing account and password information</title>
<para>Here are few notable commands to manage account information.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of commands to manage account information</title>
<tgroup cols="2">
<colspec colwidth="152pt" align="left"/>
<colspec colwidth="298pt" align="left"/>
<thead>
<row>
<entry> command </entry>
<entry> function </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>getent passwd <emphasis>user_name</emphasis></literal> </entry>
<entry> browse account information of "<literal><emphasis>user_name</emphasis></literal>" </entry>
</row>
<row>
<entry> <literal>getent shadow <emphasis>user_name</emphasis></literal> </entry>
<entry> browse shadowed account information of "<literal><emphasis>user_name</emphasis></literal>" </entry>
</row>
<row>
<entry> <literal>getent group <emphasis>group_name</emphasis></literal> </entry>
<entry> browse group information of "<literal><emphasis>group_name</emphasis></literal>" </entry>
</row>
<row>
<entry> <literal>passwd</literal> </entry>
<entry> manage password for the account </entry>
</row>
<row>
<entry> <literal>passwd -e</literal> </entry>
<entry> set one-time password for the account activation </entry>
</row>
<row>
<entry> <literal>chage</literal> </entry>
<entry> manage password aging information </entry>
</row>
</tbody>
</tgroup>
</table>
<para>You may need to have the root privilege for some functions to work. See <literal>crypt</literal>(3) for the password and data encryption.</para>
<note> <para>On the system set up with PAM and NSS as the Debian <ulink url="https://salsa.debian.org">salsa</ulink> machine, the content of local "<literal>/etc/passwd</literal>", "<literal>/etc/group</literal>" and "<literal>/etc/shadow</literal>" may not be actively used by the system. Above commands are valid even under such environment.</para> </note>
</section>
<section id="_good_password">
<title>Good password</title>
<para>When creating an account during your system installation or with the <literal>passwd</literal>(1) command, you should choose a <ulink url="https://en.wikipedia.org/wiki/Password_strength">good password</ulink> which consists of at least 6 to 8 characters including one or more characters from each of the following sets according to <literal>passwd</literal>(1).</para>
<itemizedlist>
<listitem> <para> Lower case alphabetics </para> </listitem>
<listitem> <para> Digits 0 through 9 </para> </listitem>
<listitem> <para> Punctuation marks </para> </listitem>
</itemizedlist>
<warning> <para>Do not choose guessable words for the password. Account name, social security number, phone number, address, birthday, name of your family members or pets, dictionary words, simple sequence of characters such as "12345" or "qwerty", … are all bad choice for the password.</para> </warning>
</section>
<section id="_creating_encrypted_password">
<title>Creating encrypted password</title>
<para>There are independent tools to <ulink url="https://en.wikipedia.org/wiki/Salt_(cryptography)">generate encrypted passwords with salt</ulink>.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of tools to generate password</title>
<tgroup cols="5">
<colspec colwidth="54pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="92pt" align="left"/>
<colspec colwidth="271pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> command </entry>
<entry> function </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>whois</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <literal>mkpasswd</literal> </entry>
<entry> over-featured front end to the <literal>crypt</literal>(3) library </entry>
</row>
<row>
<entry> <literal>openssl</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <literal>openssl passwd</literal> </entry>
<entry> compute password hashes (OpenSSL). <literal>passwd</literal>(1ssl) </entry>
</row>
</tbody>
</tgroup>
</table>
</section>
<section id="_pam_and_nss">
<title>PAM and NSS</title>
<para>Modern <ulink url="https://en.wikipedia.org/wiki/Unix-like">Unix-like</ulink> systems such as the Debian system provide <ulink url="https://en.wikipedia.org/wiki/Pluggable_Authentication_Modules">PAM (Pluggable Authentication Modules)</ulink> and <ulink url="https://en.wikipedia.org/wiki/Name_Service_Switch">NSS (Name Service Switch)</ulink> mechanism to the local system administrator to configure his system. The role of these can be summarizes as the following.</para>
<itemizedlist>
<listitem> <para> PAM offers a flexible authentication mechanism used by the application software thus involves password data exchange. </para> </listitem>
<listitem> <para> NSS offers a flexible name service mechanism which is frequently used by the <ulink url="https://en.wikipedia.org/wiki/C_standard_library">C standard library</ulink> to obtain the user and group name for programs such as <literal>ls</literal>(1) and <literal>id</literal>(1). </para> </listitem>
</itemizedlist>
<para>These PAM and NSS systems need to be configured consistently.</para>
<para>The notable packages of PAM and NSS systems are the following.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of notable PAM and NSS systems</title>
<tgroup cols="4">
<colspec colwidth="119pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="445pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>libpam-modules</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Pluggable Authentication Modules (basic service) </entry>
</row>
<row>
<entry> <literal>libpam-ldap</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Pluggable Authentication Module allowing LDAP interfaces </entry>
</row>
<row>
<entry> <literal>libpam-cracklib</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Pluggable Authentication Module to enable cracklib support </entry>
</row>
<row>
<entry> <literal>libpam-systemd</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Pluggable Authentication Module to register user sessions for <literal>logind</literal> </entry>
</row>
<row>
<entry> <literal>libpam-doc</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Pluggable Authentication Modules (documentation in html and text) </entry>
</row>
<row>
<entry> <literal>libc6</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> GNU C Library: Shared libraries which also provides "Name Service Switch" service </entry>
</row>
<row>
<entry> <literal>glibc-doc</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> GNU C Library: Manpages </entry>
</row>
<row>
<entry> <literal>glibc-doc-reference</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> GNU C Library: Reference manual in info, pdf and html format (non-free) </entry>
</row>
<row>
<entry> <literal>libnss-mdns</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> NSS module for Multicast DNS name resolution </entry>
</row>
<row>
<entry> <literal>libnss-ldap</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> NSS module for using LDAP as a naming service </entry>
</row>
<row>
<entry> <literal>libnss-ldapd</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> NSS module for using LDAP as a naming service (new fork of <literal>libnss-ldap</literal>) </entry>
</row>
</tbody>
</tgroup>
</table>
<itemizedlist>
<listitem> <para> "The Linux-PAM System Administrators' Guide" in <literal>libpam-doc</literal> is essential for learning PAM configuration. </para> </listitem>
<listitem> <para> "System Databases and Name Service Switch" section in <literal>glibc-doc-reference</literal> is essential for learning NSS configuration. </para> </listitem>
</itemizedlist>
<note> <para>You can see more extensive and current list by "<literal>aptitude search 'libpam-|libnss-'</literal>" command. The acronym NSS may also mean "Network Security Service" which is different from "Name Service Switch".</para> </note>
<note> <para>PAM is the most basic way to initialize environment variables for each program with the system wide default value.</para> </note>
<para>Under <ulink url="https://en.wikipedia.org/wiki/Systemd">systemd</ulink>, <literal>libpam-systemd</literal> package is installed to manage user logins by registering user sessions in the <literal>systemd</literal> control group hierarchy for <ulink url="https://en.wikipedia.org/wiki/Systemd#logind">logind</ulink>. See <literal>systemd-logind</literal>(8), <literal>logind.conf</literal>(5), and <literal>pam_systemd</literal>(8).</para>
<section id="_configuration_files_accessed_by_pam_and_nss">
<title>Configuration files accessed by PAM and NSS</title>
<para>Here are a few notable configuration files accessed by PAM and NSS.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of configuration files accessed by PAM and NSS</title>
<tgroup cols="2">
<colspec colwidth="157pt" align="left"/>
<colspec colwidth="564pt" align="left"/>
<thead>
<row>
<entry> configuration file </entry>
<entry> function </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>/etc/pam.d/<emphasis>program_name</emphasis></literal> </entry>
<entry> set up PAM configuration for the "<literal><emphasis>program_name</emphasis></literal>" program; see <literal>pam</literal>(7) and <literal>pam.d</literal>(5) </entry>
</row>
<row>
<entry> <literal>/etc/nsswitch.conf</literal> </entry>
<entry> set up NSS configuration with the entry for each service. See <literal>nsswitch.conf</literal>(5) </entry>
</row>
<row>
<entry> <literal>/etc/nologin</literal> </entry>
<entry> limit the user login by the <literal>pam_nologin</literal>(8) module </entry>
</row>
<row>
<entry> <literal>/etc/securetty</literal> </entry>
<entry> limit the tty for the root access by the <literal>pam_securetty</literal>(8) module </entry>
</row>
<row>
<entry> <literal>/etc/security/access.conf</literal> </entry>
<entry> set access limit by the <literal>pam_access</literal>(8) module </entry>
</row>
<row>
<entry> <literal>/etc/security/group.conf</literal> </entry>
<entry> set group based restraint by the <literal>pam_group</literal>(8) module </entry>
</row>
<row>
<entry> <literal>/etc/security/pam_env.conf</literal> </entry>
<entry> set environment variables by the <literal>pam_env</literal>(8) module </entry>
</row>
<row>
<entry> <literal>/etc/environment</literal> </entry>
<entry> set additional environment variables by the <literal>pam_env</literal>(8) module with the "<literal>readenv=1</literal>" argument </entry>
</row>
<row>
<entry> <literal>/etc/default/locale</literal> </entry>
<entry> set locale by <literal>pam_env</literal>(8) module with the "<literal>readenv=1 envfile=/etc/default/locale</literal>" argument (Debian) </entry>
</row>
<row>
<entry> <literal>/etc/security/limits.conf</literal> </entry>
<entry> set resource restraint (ulimit, core, …) by the <literal>pam_linits</literal>(8) module </entry>
</row>
<row>
<entry> <literal>/etc/security/time.conf</literal> </entry>
<entry> set time restraint by the <literal>pam_time</literal>(8) module </entry>
</row>
<row>
<entry> <literal>/etc/systemd/logind.conf</literal> </entry>
<entry> set <literal>systemd</literal> login manager configuration (see <literal>logind.conf</literal>(5) and <literal>systemd-logind.service</literal>(8)) </entry>
</row>
</tbody>
</tgroup>
</table>
<para>The limitation of the password selection is implemented by the PAM modules, <literal>pam_unix</literal>(8) and <literal>pam_cracklib</literal>(8). They can be configured by their arguments.</para>
<tip> <para>PAM modules use suffix "<literal>.so</literal>" for their filenames.</para> </tip>
</section>
<section id="_the_modern_centralized_system_management">
<title>The modern centralized system management</title>
<para>The modern centralized system management can be deployed using the centralized <ulink url="https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol">Lightweight Directory Access Protocol (LDAP)</ulink> server to administer many Unix-like and non-Unix-like systems on the network. The open source implementation of the Lightweight Directory Access Protocol is <ulink url="https://www.openldap.org/">OpenLDAP Software</ulink>.</para>
<para>The LDAP server provides the account information through the use of PAM and NSS with <literal>libpam-ldap</literal> and <literal>libnss-ldap</literal> packages for the Debian system. Several actions are required to enable this (I have not used this setup and the following is purely secondary information. Please read this in this context.).</para>
<itemizedlist>
<listitem> <para> You set up a centralized LDAP server by running a program such as the stand-alone LDAP daemon, <literal>slapd</literal>(8). </para> </listitem>
<listitem>
<para> You change the PAM configuration files in the "<literal>/etc/pam.d/</literal>" directory to use "<literal>pam_ldap.so</literal>" instead of the default "<literal>pam_unix.so</literal>". </para>
<itemizedlist>
<listitem> <para> Debian uses "<literal>/etc/pam_ldap.conf</literal>" as the configuration file for <literal>libpam-ldap</literal> and "<literal>/etc/pam_ldap.secret</literal>" as the file to store the password of the root. </para> </listitem>
</itemizedlist>
</listitem>
<listitem>
<para> You change the NSS configuration in the "<literal>/etc/nsswitch.conf</literal>" file to use "<literal>ldap</literal>" instead of the default ("<literal>compat</literal>" or "<literal>file</literal>"). </para>
<itemizedlist>
<listitem> <para> Debian uses "<literal>/etc/libnss-ldap.conf</literal>" as the configuration file for <literal>libnss-ldap</literal>. </para> </listitem>
</itemizedlist>
</listitem>
<listitem> <para> You must make <literal>libpam-ldap</literal> to use <ulink url="https://en.wikipedia.org/wiki/Transport_Layer_Security">SSL (or TLS)</ulink> connection for the security of password. </para> </listitem>
<listitem> <para> You may make <literal>libnss-ldap</literal> to use <ulink url="https://en.wikipedia.org/wiki/Transport_Layer_Security">SSL (or TLS)</ulink> connection to ensure integrity of data at the cost of the LDAP network overhead. </para> </listitem>
<listitem> <para> You should run <literal>nscd</literal>(8) locally to cache any LDAP search results in order to reduce the LDAP network traffic. </para> </listitem>
</itemizedlist>
<para>See documentations in <literal>pam_ldap.conf</literal>(5) and "<literal>/usr/share/doc/libpam-doc/html/</literal>" offered by the <literal>libpam-doc</literal> package and "<literal>info libc 'Name Service Switch'</literal>" offered by the <literal>glibc-doc</literal> package.</para>
<para>Similarly, you can set up alternative centralized systems with other methods.</para>
<itemizedlist>
<listitem>
<para> Integration of user and group with the Windows system. </para>
<itemizedlist>
<listitem> <para> Access <ulink url="https://en.wikipedia.org/wiki/Windows_domain">Windows domain</ulink> services by the <literal>winbind</literal> and <literal>libpam_winbind</literal> packages. </para> </listitem>
<listitem> <para> See <literal>winbindd</literal>(8) and <ulink url="https://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/integrate-ms-networks.html">Integrating MS Windows Networks with Samba</ulink>. </para> </listitem>
</itemizedlist>
</listitem>
<listitem>
<para> Integration of user and group with the legacy Unix-like system. </para>
<itemizedlist>
<listitem> <para> Access <ulink url="https://en.wikipedia.org/wiki/Network_Information_Service">NIS (originally called YP)</ulink> or <ulink url="https://en.wikipedia.org/wiki/NIS+">NIS+</ulink> by the <literal>nis</literal> package. </para> </listitem>
<listitem> <para> See <ulink url="https://tldp.org/HOWTO/NIS-HOWTO/">The Linux NIS(YP)/NYS/NIS+ HOWTO</ulink>. </para> </listitem>
</itemizedlist>
</listitem>
</itemizedlist>
</section>
<section id="_why_gnu_su_does_not_support_the_wheel_group">
<title>"Why GNU su does not support the wheel group"</title>
<para>This is the famous phrase at the bottom of the old "<literal>info su</literal>" page by Richard M. Stallman. Not to worry: the current <literal>su</literal> command in Debian uses PAM, so that one can restrict the ability to use <literal>su</literal> to the <literal>root</literal> group by enabling the line with "<literal>pam_wheel.so</literal>" in "<literal>/etc/pam.d/su</literal>".</para>
</section>
<section id="_stricter_password_rule">
<title>Stricter password rule</title>
<para>Installing the <literal>libpam-cracklib</literal> package enables you to force stricter password rule.</para>
<para>On a typical GNOME system which automatically installs <literal>libpam-gnome-keyring</literal>, "<literal>/etc/pam.d/common-password</literal>" looks like:</para>
<screen># here are the per-package modules (the "Primary" block)
password requisite pam_cracklib.so retry=3 minlen=8 difok=3
password [success=1 default=ignore] pam_unix.so obscure use_authtok try_first_pass yescrypt
# here's the fallback if no module succeeds
password requisite pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
password required pam_permit.so
# and here are more per-package modules (the "Additional" block)
password optional pam_gnome_keyring.so
# end of pam-auth-update config</screen>
</section>
</section>
<section id="_security_of_authentication">
<title>Security of authentication</title>
<note> <para>The information here <emphasis role="strong">may not be sufficient</emphasis> for your security needs but it should be a <emphasis role="strong">good start</emphasis>.</para> </note>
<section id="_secure_password_on_the_internet">
<title>Secure password on the Internet</title>
<para>Many popular transportation layer services communicate messages including password authentication in the plain text. It is very bad idea to transmit password in the plain text over the wild Internet where it can be intercepted. You can run these services over "<ulink url="https://en.wikipedia.org/wiki/Transport_Layer_Security">Transport Layer Security</ulink>" (TLS) or its predecessor, "Secure Sockets Layer" (SSL) to secure entire communication including password by the encryption.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of insecure and secure services and ports</title>
<tgroup cols="4">
<colspec colwidth="119pt" align="left"/>
<colspec colwidth="27pt" align="left"/>
<colspec colwidth="108pt" align="left"/>
<colspec colwidth="27pt" align="left"/>
<thead>
<row>
<entry> insecure service name </entry>
<entry> port </entry>
<entry> secure service name </entry>
<entry> port </entry>
</row>
</thead>
<tbody>
<row>
<entry> www (http) </entry>
<entry> 80 </entry>
<entry> https </entry>
<entry> 443 </entry>
</row>
<row>
<entry> smtp (mail) </entry>
<entry> 25 </entry>
<entry> ssmtp (smtps) </entry>
<entry> 465 </entry>
</row>
<row>
<entry> ftp-data </entry>
<entry> 20 </entry>
<entry> ftps-data </entry>
<entry> 989 </entry>
</row>
<row>
<entry> ftp </entry>
<entry> 21 </entry>
<entry> ftps </entry>
<entry> 990 </entry>
</row>
<row>
<entry> telnet </entry>
<entry> 23 </entry>
<entry> telnets </entry>
<entry> 992 </entry>
</row>
<row>
<entry> imap2 </entry>
<entry> 143 </entry>
<entry> imaps </entry>
<entry> 993 </entry>
</row>
<row>
<entry> pop3 </entry>
<entry> 110 </entry>
<entry> pop3s </entry>
<entry> 995 </entry>
</row>
<row>
<entry> ldap </entry>
<entry> 389 </entry>
<entry> ldaps </entry>
<entry> 636 </entry>
</row>
</tbody>
</tgroup>
</table>
<para>The encryption costs CPU time. As a CPU friendly alternative, you can keep communication in plain text while securing just the password with the secure authentication protocol such as "Authenticated Post Office Protocol" (APOP) for POP and "Challenge-Response Authentication Mechanism MD5" (CRAM-MD5) for SMTP and IMAP. (For sending mail messages over the Internet to your mail server from your mail client, it is recently popular to use new message submission port 587 instead of traditional SMTP port 25 to avoid port 25 blocking by the network provider while authenticating yourself with CRAM-MD5.)</para>
</section>
<section id="_secure_shell">
<title>Secure Shell</title>
<para>The <ulink url="https://en.wikipedia.org/wiki/Secure_Shell">Secure Shell (SSH)</ulink> program provides secure encrypted communications between two untrusted hosts over an insecure network with the secure authentication. It consists of the <ulink url="https://www.openssh.org/">OpenSSH</ulink> client, <literal>ssh</literal>(1), and the <ulink url="https://www.openssh.org/">OpenSSH</ulink> daemon, <literal>sshd</literal>(8). This SSH can be used to tunnel an insecure protocol communication such as POP and X securely over the Internet with the port forwarding feature.</para>
<para>The client tries to authenticate itself using host-based authentication, public key authentication, challenge-response authentication, or password authentication. The use of public key authentication enables the remote password-less login. See <xref linkend="_the_remote_access_server_and_utilities_ssh"/>.</para>
</section>
<section id="_extra_security_measures_for_the_internet">
<title>Extra security measures for the Internet</title>
<para>Even when you run secure services such as <ulink url="https://en.wikipedia.org/wiki/Secure_Shell">Secure Shell (SSH)</ulink> and <ulink url="https://en.wikipedia.org/wiki/Point-to-point_tunneling_protocol">Point-to-point tunneling protocol (PPTP)</ulink> servers, there are still chances for the break-ins using brute force password guessing attack etc. from the Internet. Use of the firewall policy (see <xref linkend="_netfilter_infrastructure"/>) together with the following security tools may improve the security situation.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of tools to provide extra security measures</title>
<tgroup cols="4">
<colspec colwidth="86pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="418pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>knockd</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> small port-knock daemon <literal>knockd</literal>(1) and client <literal>knock</literal>(1) </entry>
</row>
<row>
<entry> <literal>fail2ban</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> ban IPs that cause multiple authentication errors </entry>
</row>
<row>
<entry> <literal>libpam-shield</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> lock out remote attackers trying password guessing </entry>
</row>
</tbody>
</tgroup>
</table>
</section>
<section id="_securing_the_root_password">
<title>Securing the root password</title>
<para>To prevent people to access your machine with root privilege, you need to make following actions.</para>
<itemizedlist>
<listitem> <para> Prevent physical access to the hard disk </para> </listitem>
<listitem> <para> Lock UEFI/BIOS and prevent booting from the removable media </para> </listitem>
<listitem> <para> Set password for GRUB interactive session </para> </listitem>
<listitem> <para> Lock GRUB menu from editing </para> </listitem>
</itemizedlist>
<para>With physical access to hard disk, resetting the password is relatively easy with following steps.</para>
<orderedlist>
<listitem> <para> Move the hard disk to a PC with CD bootable UEFI/BIOS. </para> </listitem>
<listitem> <para> Boot system with a rescue media (Debian boot disk, Knoppix CD, GRUB CD, …). </para> </listitem>
<listitem> <para> Mount root partition with read/write access. </para> </listitem>
<listitem> <para> Edit "<literal>/etc/passwd</literal>" in the root partition and make the second entry for the <literal>root</literal> account empty. </para> </listitem>
</orderedlist>
<para>If you have edit access to the GRUB menu entry (see <xref linkend="_stage_2_the_boot_loader"/>) for <literal>grub-rescue-pc</literal> at boot time, it is even easier with following steps.</para>
<orderedlist>
<listitem> <para> Boot system with the kernel parameter changed to something like "<literal>root=/dev/hda6 rw init=/bin/sh</literal>". </para> </listitem>
<listitem> <para> Edit "<literal>/etc/passwd</literal>" and make the second entry for the <literal>root</literal> account empty. </para> </listitem>
<listitem> <para> Reboot system. </para> </listitem>
</orderedlist>
<para>The root shell of the system is now accessible without password.</para>
<note> <para>Once one has root shell access, he can access everything on the system and reset any passwords on the system. Further more, he may compromise password for all user accounts using brute force password cracking tools such as <literal>john</literal> and <literal>crack</literal> packages (see <xref linkend="_system_security_and_integrity_check"/>). This cracked password may lead to compromise other systems.</para> </note>
<para>The only reasonable software solution to avoid all these concerns is to use software encrypted root partition (or "<literal>/etc</literal>" partition) using <ulink url="https://en.wikipedia.org/wiki/Dm-crypt">dm-crypt</ulink> and initramfs (see <xref linkend="_data_encryption_tips"/>). You always need password to boot the system, though.</para>
</section>
</section>
<section id="_other_access_controls">
<title>Other access controls</title>
<para>There are access controls to the system other than the password based authentication and file permissions.</para>
<note> <para>See <xref linkend="_alt_sysrq_key"/> for restricting the kernel <ulink url="https://en.wikipedia.org/wiki/Secure_attention_key">secure attention key (SAK)</ulink> feature.</para> </note>
<section id="_access_control_lists">
<title>Access control lists (ACLs)</title>
<para>ACLs are a superset of the regular permissions as explained in <xref linkend="_filesystem_permissions" />.</para>
<para>You encounter ACLs in action on modern desktop environment. When a formatted USB storage device is auto mounted as, e.g., "<literal>/media/penguin/USBSTICK</literal>", a normal user <literal>penguin</literal> can execute:</para>
<screen> $ cd /media/penguin
$ ls -la
total 16
drwxr-x---+ 1 root root 16 Jan 17 22:55 .
drwxr-xr-x 1 root root 28 Sep 17 19:03 ..
drwxr-xr-x 1 penguin penguin 18 Jan 6 07:05 USBSTICK</screen>
<para>"<literal>+</literal>" in the 11th column indicates ACLs are in action. Without ACLs, a normal user <literal>penguin</literal> shouldn't be able to list like this since <literal>penguin</literal> isn't in <literal>root</literal> group. You can see ACLs as:</para>
<screen> $ getfacl .
# file: .
# owner: root
# group: root
user::rwx
user:penguin:r-x
group::---
mask::r-x
other::---
</screen>
<para>Here:</para>
<itemizedlist>
<listitem> <para>"<literal>user::rwx</literal>", "<literal>group::---</literal>", and "<literal>other::---</literal>" correspond to the regular owner, group, and other permissions.</para> </listitem>
<listitem> <para>The ACL "<literal>user:penguin:r-x</literal>" allows a normal user <literal>penguin</literal> to have "<literal>r-x</literal>" permissions. This enabled "<literal>ls -la</literal>" to list directory content.</para> </listitem>
<listitem> <para>The ACL "<literal>mask::r-x</literal>" sets the upper bound of permissions.</para> </listitem>
</itemizedlist>
<para>See "<ulink url="https://www.usenix.org/legacy/events/usenix03/tech/freenix03/full_papers/gruenbacher/gruenbacher.pdf">POSIX Access Control Lists on Linux</ulink>", <literal>acl</literal>(5), <literal>getfacl</literal>(1), and <literal>setfacl</literal>(1) for more.</para>
<!--
<para> https://documentation.suse.com/ja-jp/sles/15-SP1/html/SLES-all/cha-security-acls.html </para>
<para> https://hana-shin.hatenablog.com/entry/2022/05/31/221357</para>
<para> https://www.reddit.com/r/linux/comments/170crnt/acl_101_a_visual_guide_to_accesscontrol_lists/ </para>
<para> https://serverfault.com/questions/1138532/linux-debian-acl-is-default-mask-overriden-by-something-in-ftp </para>
<para> https://www.redhat.com/sysadmin/linux-access-control-lists </para>
<para> https://wiki.debian.org/Permissions </para>
<para> </para>
-->
</section>
<section id="_sudo">
<title>sudo</title>
<para><literal>sudo</literal>(8) is a program designed to allow a sysadmin to give limited root privileges to users and log root activity. <literal>sudo</literal> requires only an ordinary user's password. Install <literal>sudo</literal> package and activate it by setting options in "<literal>/etc/sudoers</literal>". See configuration example at "<literal>/usr/share/doc/sudo/examples/sudoers</literal>" and <xref linkend="_sudo_configuration"/>.</para>
<para>My usage of <literal>sudo</literal> for the single user system (see <xref linkend="_sudo_configuration"/>) is aimed to protect myself from my own stupidity. Personally, I consider using <literal>sudo</literal> a better alternative than using the system from the root account all the time. For example, the following changes the owner of "<literal><emphasis>some_file</emphasis></literal>" to "<literal><emphasis>my_name</emphasis></literal>".</para>
<screen>$ sudo chown <emphasis>my_name</emphasis> <emphasis>some_file</emphasis></screen>
<para>Of course if you know the root password (as self-installed Debian users do), any command can be run under root from any user's account using "<literal>su -c</literal>".</para>
</section>
<section id="_policykit">
<title>PolicyKit</title>
<para><ulink url="https://en.wikipedia.org/wiki/PolicyKit">PolicyKit</ulink> is an operating system component for controlling system-wide privileges in Unix-like operating systems.</para>
<para>Newer GUI applications are not designed to run as privileged processes. They talk to privileged processes via PolicyKit to perform administrative operations.</para>
<para>PolicyKit limits such operations to user accounts belonging to the <literal>sudo</literal> group on the Debian system.</para>
<para>See <literal>polkit</literal>(8).</para>
</section>
<section id="_restricting_access_to_some_server_services">
<title>Restricting access to some server services</title>
<para>For system security, it is a good idea to disable as much server programs as possible. This becomes critical for network servers. Having unused servers, activated either directly as <ulink url="https://en.wikipedia.org/wiki/Daemon_(computer_software)">daemon</ulink> or via <ulink url="https://en.wikipedia.org/wiki/Super-server">super-server</ulink> program, are considered security risks.</para>
<para>Many programs, such as <literal>sshd</literal>(8), use PAM based access control. There are many ways to restrict access to some server services.</para>
<itemizedlist>
<listitem> <para> configuration files: "<literal>/etc/default/<emphasis>program_name</emphasis></literal>" </para> </listitem>
<listitem> <para> Systemd service unit configuration for <ulink url="https://en.wikipedia.org/wiki/Daemon_(computer_software)">daemon</ulink> </para> </listitem>
<listitem> <para> <ulink url="https://en.wikipedia.org/wiki/Pluggable_Authentication_Modules">PAM (Pluggable Authentication Modules)</ulink> </para> </listitem>
<listitem> <para> "<literal>/etc/inetd.conf</literal>" for <ulink url="https://en.wikipedia.org/wiki/Super-server">super-server</ulink> </para> </listitem>
<listitem> <para> "<literal>/etc/hosts.deny</literal>" and "<literal>/etc/hosts.allow</literal>" for <ulink url="https://en.wikipedia.org/wiki/TCP_Wrapper">TCP wrapper</ulink>, <literal>tcpd</literal>(8) </para> </listitem>
<listitem> <para> "<literal>/etc/rpc.conf</literal>" for <ulink url="https://en.wikipedia.org/wiki/Open_Network_Computing_Remote_Procedure_Call">Sun RPC</ulink> </para> </listitem>
<listitem> <para> "<literal>/etc/at.allow</literal>" and "<literal>/etc/at.deny</literal>" for <literal>atd</literal>(8) </para> </listitem>
<listitem> <para> "<literal>/etc/cron.allow</literal>" and "<literal>/etc/cron.deny</literal>" for <literal>crontab</literal>(1) </para> </listitem>
<listitem> <para> <ulink url="https://en.wikipedia.org/wiki/Firewall">Network firewall</ulink> of <ulink url="https://en.wikipedia.org/wiki/Netfilter">netfilter</ulink> infrastructure </para> </listitem>
</itemizedlist>
<para>See <xref linkend="_system_management_operations"/>, <xref linkend="_configuration_files_accessed_by_pam_and_nss"/>, and <xref linkend="_netfilter_infrastructure"/>.</para>
<tip> <para><ulink url="https://en.wikipedia.org/wiki/Open_Network_Computing_Remote_Procedure_Call">Sun RPC</ulink> services need to be active for <ulink url="https://en.wikipedia.org/wiki/Network_File_System_(protocol)">NFS</ulink> and other RPC based programs.</para> </tip>
<tip> <para>If you have problems with remote access in a recent Debian system, comment out offending configuration such as "<literal>ALL: PARANOID</literal>" in "<literal>/etc/hosts.deny</literal>" if it exists. (But you must be careful on security risks involved with this kind of action.)</para> </tip>
</section>
<section id="_linux_security_features">
<title>Linux security features</title>
<para>Linux kernel has evolved and supports security features not found in traditional UNIX implementations.</para>
<para>Linux supports <ulink url="https://en.wikipedia.org/wiki/Extended_file_attributes">extended attributes</ulink> which extend the traditional UNIX attributes (see <literal>xattr</literal>(7)).</para>
<para>Linux divides the privileges traditionally associated with superuser into distinct units, known as <literal>capabilities</literal>(7), which can be independently enabled and disabled. Capabilities are a per-thread attribute since kernel version 2.2.</para>
<para>The <ulink url="https://en.wikipedia.org/wiki/Linux_Security_Modules">Linux Security Module (LSM) framework</ulink> provides a <ulink url="https://en.wikipedia.org/wiki/Mandatory_access_control">mechanism for various security checks</ulink> to be hooked by new kernel extensions. For example:</para>
<itemizedlist>
<listitem> <para> <ulink url="https://en.wikipedia.org/wiki/AppArmor">AppArmor</ulink></para> </listitem>
<listitem> <para> <ulink url="https://en.wikipedia.org/wiki/Security-Enhanced_Linux">Security-Enhanced Linux (SELinux)</ulink> </para> </listitem>
<listitem> <para> <ulink url="https://en.wikipedia.org/wiki/Smack_(software)">Smack (Simplified Mandatory Access Control Kernel)</ulink> </para> </listitem>
<listitem> <para> <ulink url="https://en.wikipedia.org/wiki/Tomoyo_Linux">Tomoyo Linux</ulink> </para> </listitem>
</itemizedlist>
<para>Since these extensions may tighten privilege model tighter than the ordinary Unix-like security model policies, even the root power may be restricted. You are advised to read the <ulink url="https://www.kernel.org/doc/html/latest/admin-guide/LSM/index.html">Linux Security Module (LSM) framework document at kernel.org</ulink>.</para>
<para>Linux <ulink url="https://en.wikipedia.org/wiki/Linux_namespaces">namespaces</ulink> wrap a global system resource in an abstraction that makes it appear to the processes within the namespace that they have their own isolated instance of the global resource. Changes to the global resource are visible to other processes that are members of the namespace, but are invisible to other processes. Since kernel version 5.6, there are 8 kinds of namespaces (see <literal>namespaces</literal>(7), <literal>unshare</literal>(1), <literal>nsenter</literal>(1)).</para>
<para>As of Debian 11 Bullseye (2021), Debian uses unified cgroup hierarchy (a.k.a. <ulink url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html">cgroups-v2</ulink>).</para>
<para>Usage examples of <ulink url="https://en.wikipedia.org/wiki/Linux_namespaces">namespaces</ulink> with <ulink url="https://en.wikipedia.org/wiki/Cgroups">cgroups</ulink> to isolate their processes and to allow resource control are:</para>
<itemizedlist>
<listitem> <para> <ulink url="https://en.wikipedia.org/wiki/Systemd">Systemd</ulink>. See <xref linkend="_systemd_init"/>.</para> </listitem>
<listitem> <para> <ulink url="https://en.wikipedia.org/wiki/Sandbox_(computer_security)">Sandbox environment</ulink>. See <xref linkend="_sandbox"/>. </para> </listitem>
<listitem> <para> <ulink url="https://en.wikipedia.org/wiki/List_of_Linux_containers">Linux containers</ulink> such as <ulink url="https://en.wikipedia.org/wiki/Docker_(software)">Docker</ulink>, <ulink url="https://en.wikipedia.org/wiki/LXC">LXC</ulink>. See <xref linkend="_virtualized_system"/>. </para> </listitem>
</itemizedlist>
<para>These functionalities can't be realized by <xref linkend="_normal_unix_authentication"/>. These advanced topics are mostly out-of-scope for this introductory document.</para>
</section>
</section>
</chapter>
|