File: Auth.ref.txt

package info (click to toggle)
debian-reference 2.24
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 20,088 kB
  • ctags: 35
  • sloc: xml: 70,510; sh: 616; makefile: 352; perl: 221; sed: 3
file content (307 lines) | stat: -rw-r--r-- 20,192 bytes parent folder | download
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
= Do not use Edit(GUI) button. =

[[TableOfContents(4)]]

Copyright 2007, 2008  Osamu Aoki GPL, (Please agree to GPL, GPL2, and any version of GPL which is compatible with DSFG if you update any part of wiki page)

Generated HTML is at "[http://people.debian.org/~osamu/pub/getwiki/html/ch05.en.html Debian Reference: Chapter 5. Authentication]".

I welcome your contributions to update this wiki page. You must follow these rules:
 * Do not use Edit(GUI) button of MoinMoin.
 * You can update anytime for:
  * grammar errors
  * spelling errors
  * moved URL location
  * package name transition adjustment (emacs23 etc.)
  * clearly broken script.
 * Before updating this wiki content:
  * Read "[http://wiki.debian.org/DebianReference/Test Guide for contributing to Debian Reference]".

= Authentication =

== Normal Unix authentication ==

Normal Unix authentication is provided by the {{{pam_unix.so}}} method under the [http://en.wikipedia.org/wiki/Pluggable_Authentication_Modules PAM (Pluggable Authentication Modules)]. Its 3 important configuration files, with "{{{:}}}" separated entries, are:

|| The 3 important configuration files for pam_unix.o. || || || || ||
|| '''file''' || '''permission''' || '''user''' || '''group''' || '''description''' ||
|| {{{/etc/passwd}}} || {{{-rw-r--r--}}} || {{{root}}} || {{{root}}} || The (sanitized) user account information. ||
|| {{{/etc/shadow}}} || {{{-rw-r-----}}} || {{{root}}} || {{{shadow}}} || The secure user account information. ||
|| {{{/etc/group}}} || {{{-rw-r--r--}}} || {{{root}}} || {{{root}}} || The group information. ||

The {{{/etc/passwd}}} file contains:
{{{
...
user1:x:1000:1000:User1 Name,,,:/home/user1:/bin/bash
user2:x:1001:1001:User2 Name,,,:/home/user2:/bin/bash
...
}}}
As  explained in {{{man 5 passwd}}}, each "{{{:}}}" separated entry of this file means:
 * login name
 * password specification entry
 * numerical user ID
 * numerical group ID
 * user name or comment field
 * user home directory
 * optional user command interpreter

The second entry of {{{/etc/passwd}}} was used for the encrypted password entry.  After the introduction of {{{/etc/shadow}}}, this entry is used for the password specification entry.

|| The second entry content of {{{/etc/passwd}}}. || ||
|| '''content''' || '''meaning''' ||
|| (empty) || passwordless account ||
|| x || the encrypted password is in the {{{/etc/shadow}}} file ||
|| * || no login for this account ||
|| ! || no login for this account ||

The {{{/etc/shadow}}} file contains:
{{{
...
user1:$1$Xop0FYH9$IfxyQwBe9b8tiyIkt2P4F/:13262:0:99999:7:::
user2:$1$vXGZLVbS$ElyErNf/agUDsm1DehJMS/:13261:0:99999:7:::
...
}}}

As explained in {{{man 5 shadow}}}, each "{{{:}}}" separated entry of this file means:
 * login name
 * encrypted password.  The initial "{{{$1$}}}" indicates use of the MD5 encryption. The "*" indicate no login.
 * days since Jan 1, 1970 that password was last changed
 * days before password may be changed
 * days after which password must be changed
 * days before password is to expire that user is warned

The {{{/etc/group}}} file contains:
{{{
...
group1:x:20:user1,user2
...
}}}
As explained in {{{man 5 shadow}}}, each "{{{:}}}" separated entry of this file means:

 * group name
 * encrypted password (not really used)
 * numerical group ID.
 * "," separated list of user names.

The {{{/etc/gshadow}}} file provides the similar function as the {{{/etc/shadow}}} file for the {{{/etc/group}}} file but is not really used.

(!) The actual group membership of a user may be dynamically added if "auth optional pam_group.so" line is added to {{{/etc/pam.d/common-auth}}} and set it in {{{/etc/security/group.conf}}}.  See {{{pam_group}}}(8).

(!) The {{{base-passwd}}} package contains an authoritative list of the user and the group: {{{/usr/share/doc/base-passwd/users-and-groups.html}}}.

== Manage account and password information ==

Here are few notable commands to manage account information:

|| List of commands to manage account information. || ||
|| '''command''' || '''function''' ||
|| {{{getent passwd <user_name>}}} || browse account information of {{{<user_name>}}} ||
|| {{{getent shadow <user_name>}}} || browse shadowed account information of {{{<user_name>}}} ||
|| {{{getent group <group_name>}}} || browse group information of {{{<group_name>}}} ||
|| {{{passwd}}} || manage password for the account ||
|| {{{passwd -e}}} || set one-time password for the account activation ||
|| {{{chage}}} || manage password aging information ||
You may need to have the root privilege for some functions to work. See {{{man 3 crypt}}} for the password and data encryption.

(!) On the system set up with PAM and NSS as the Debian [http://alioth.debian.org alioth] machine, the content of the local {{{/etc/passwd}}}, {{{/etc/group}}} and {{{/etc/shadow}}} files may not be actively used by the system thus requiring above commands to be used instead of the editor.

== Good password ==

When creating an account during your system installation or with the {{{passwd}}}(1) command, you should choose a [http://en.wikipedia.org/wiki/Password_strength good password] which consists of 6 to 8 characters including one or more characters from each of the following sets (per the {{{passwd}}}(1) manpage):
 * lower case alphabetics
 * digits 0 through 9
 * punctuation marks

/!\ Do not chose guessable words for the password.

== Creating encrypted password ==

There are independent tools to generate encrypted password with salt:

|| List of tools to generate password. || 1 || 2 || 3 || ||
|| '''package''' || '''popcon''' || '''size''' || '''command''' || '''function''' ||
|| {{{whois}}} || || - ||  {{{mkpasswd}}} ||over-featured front end to the {{{crypt}}}(3) library ||
|| {{{openssl}}} || || - ||  {{{openssl passwd}}}|| compute password hashes (OpenSSL). {{{passwd}}}(1ssl) ||

== PAM and NSS ==

Modern Unix-like systems such as the Debian system provide [http://en.wikipedia.org/wiki/Pluggable_Authentication_Modules PAM (Pluggable Authentication Modules)] and [http://en.wikipedia.org/wiki/Name_Service_Switch NSS (Name Service Switch)] mechanism to the local system administrator to configure his system.  The role of these can be summarizes as:

 * PAM offers a flexible authentication mechanism used by the application software thus involves password data exchange.
 * NSS offers a flexible name service mechanism which is frequently used by the C library to obtain the user and group name for programs such as {{{ls}}} and {{{id}}}.

These PAM and NSS systems need to be configured consistently.

The notable packages of PAM and NSS systems are:
|| List of notable PAM and NSS systems. || 1 || 2 || 3 ||
|| '''package''' || '''popcon''' || '''size''' || '''description''' ||
|| {{{libpam-modules}}} || - || - || Pluggable Authentication Modules for PAM ||
|| {{{libpam-ldap}}} || - || - || Pluggable Authentication Module allowing LDAP interfaces ||
|| {{{libpam-cracklib}}} || - || - || Pluggable Authentication Module to enable cracklib support ||
|| {{{libc6}}} || - || - || GNU C Library: Shared libraries which also provides "Name Service Switch" service ||
|| {{{libnss-mdns}}} || - || - || NSS module for Multicast DNS name resolution ||
|| {{{libnss-ldap}}} || - || - || NSS module for using LDAP as a naming service ||
|| {{{libnss-ldapd}}} || - || - || NSS module for using LDAP as a naming service (new folk of {{{libnss-ldap}}}) ||

(!) You can see more extensive and current list by "{{{aptitude search 'libpam-|libnss-'}}}" command.  The acronym NSS may also mean "Network Security Service" which is different from "Name Service Switch".  

(!) PAM is the most basic way to initialize environment variables for each program with the system wide default value.

=== Configuration files accessed by the PAM and NSS ===

Here are few notable configuration files accessed by the PAM:

|| List of configuration files accessed by the PAM. || ||
|| '''configuration file''' || '''function''' ||
|| {{{/etc/pam.d/<program_name>}}} || set up PAM configuration for the {{{<program_name>}}}. See manpage of {{{pam}}}(7). ||
|| {{{/etc/nsswitch.conf}}} || set up NSS configuration with the entry for each service. See manpage of {{{nsswitch.conf}}}(5). ||
|| {{{/etc/nologin}}} || accessed by {{{pam_nologin.so}}} module to limit the user login. ||
|| {{{/etc/securetty}}} || accessed by {{{pam_securetty.so}}} module to limit the tty for the root access. ||
|| {{{/etc/security/access.conf}}} || accessed by {{{pam_access.so}}} module to set access limit. ||
|| {{{/etc/security/group.conf}}} || accessed by {{{pam_group.so}}} module to set group based restraint. ||
|| {{{/etc/security/pam_env.conf}}} || accessed by {{{pam_env.so}}} module to set environment variables. ||
|| {{{/etc/environment}}} || accessed by {{{pam_env.so}}} module with {{{readenv=1}}} argument to set environment variables additionally. ||
|| {{{/etc/default/locale}}} || accessed by {{{pam_env.so}}} module with argument {{{readenv=1 envfile=/etc/default/locale}}} to set locale (Debian). ||
|| {{{/etc/security/limits.conf}}} || accessed by {{{pam_linits.so}}} module to set resource restraint (ulimit, core, ...). ||
|| {{{/etc/security/time.conf}}} || accessed by {{{pam_time.so}}} module to set time restraint. ||

The limitation of the password selection is implemented by the PAM modules, {{{pam_unix.so}}} and {{{pam_cracklib.so}}} and configuring them with arguments. 

=== The modern centralized system management ===

The modern centralized system management can be deployed using the centralized [http://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol Lightweight Directory Access Protocol (LDAP)] 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 [http://www.openldap.org/ OpenLDAP Software].

The LDAP server provides the account information through the use of PAM and NSS with {{{libpam-ldap}}} and {{{libnss-ldap}}} packages for the Debian system. Several actions are required to enable this (I have not used this setup and based purely on secondary information.  Please read this in this context.):

 * You set up a centralized LDAP server by running program such as stand-alone LDAP daemon, {{{slapd}}}.
 * You change the PAM configuration files in the {{{/etc/pam.d/}}} directory to use {{{pam_ldap.so}}} instead of the default {{{pam_unix.so}}}.
 * You change the NSS configuration in the {{{/etc/nsswitch.conf}}} file to use {{{ldap}}} instead of the default ({{{compat}}} or {{{file}}}).
 * Debian uses {{{/etc/pam_ldap.conf}}} as {{{libpam-ldap}}}'s configuration file and {{{/etc/pam_ldap.secret}}} as the file to store the password of the rootbinddn.
 * You must make {{{libpam-ldap}}} to use SSL (or TLS) connection for the security of password.  
 * You may make {{{libnss-ldap}}} to use SSL (or TLS) connection using {{{/etc/libnss-ldap.conf}}} to ensure integrity of data at the cost of the LDAP network overhead.
 * You should run {{{nscd}}} locally to cache any LDAP search results in order to reduce the LDAP network traffic.

See documentations in {{{/usr/share/doc/libpam-doc/html/}}} offered by {{{libpam-doc}}} package and "{{{info libc 'Name Service Switch'}}}" offered by {{{glibc-doc}}} package.

Similarly, you can set up alternative centralized systems with:

 * NIS or NIS+ with the traditional Unix systems.
 * winbind with Windows NT and SAMBA.

=== "Why GNU su does not support the wheel group" ===

This is the famous phrase at the bottom of the old "{{{info su}}}" page by Richard M. Stallman.  Not to worry: the current {{{su}}} in Debian uses PAM, so that one can restrict the ability to use {{{su}}} to {{{root}}} group by enabling the line with {{{pam_wheel.so}}} in {{{/etc/pam.d/su}}}.

=== Stricter password rule ===

Installing the {{{libpam-cracklib}}} package will enable you to force stricter password rule, for example, by having active lines in  {{{/etc/pam.d/common-password}}} as:
{{{
password required pam_cracklib.so retry=3 minlen=9 difok=3
password required pam_unix.so use_authtok nullok md5
}}}

== Other access controls ==

(!) See @{@altsysrq@}@ for restricting the kernel SAK feature.

=== sudo ===

{{{sudo}}} is a program designed to allow a sysadmin to give limited root privileges to users and log root activity. {{{sudo}}} requires only an ordinary user's password.  Install {{{sudo}}} package and activate it by setting options in {{{/etc/sudoers}}}.  See configuration example at {{{/usr/share/doc/sudo/examples/sudoers}}}.

My usage of {{{sudo}}} for the single user system (see @{@sudoconfiguration@}@) is aimed to protect myself from my own stupidity. Personally, I consider using {{{sudo}}} a better alternative to using the system from the root account all the time.   For example, following will change the owner of <some_file> to <my_name>:
{{{
$ sudo chown <my_name> <some_file>
}}}

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 "{{{su -c}}}".

=== SELinux ===

[http://en.wikipedia.org/wiki/Security-Enhanced_Linux Security-Enhanced Linux (SELinux)]is a framework to tighten privilege model tighter than the ordinary Unix-like security model with the [http://en.wikipedia.org/wiki/Mandatory_access_control mandatory access control (MAC)] policies.  The root power may be restricted under some conditions.

=== Restricting access to some server services ===

The Internet ''super-server'', {{{inetd}}}, is started at boot time by {{{/etc/rc2.d/S20inetd}}} (for {{{RUNLEVEL=2}}}), which is a symlink to {{{/etc/init.d/inetd}}}.  Essentially, {{{inetd}}} allows one running daemon to invoke several others, reducing load on the system.

Whenever a request for service arrives, its protocol and service are identified by looking them up in the databases in {{{/etc/protocols}}} and {{{/etc/services}}}.  {{{inetd}}} then looks up a normal Internet service in the {{{/etc/inetd.conf}}} database, or a Sun-RPC based service in {{{/etc/rpc.conf}}}.

For system security, make sure to disable unused services in {{{/etc/inetd.conf}}}.  Sun-RPC services need to be active for NFS and other RPC-based programs.

Sometimes, {{{inetd}}} does not start the intended server directly but starts the {{{tcpd}}} TCP/IP daemon wrapper program with the intended server name as its argument in {{{/etc/inetd.conf}}}.  In this case, {{{tcpd}}} runs the appropriate server program after logging the request and doing some additional checks using {{{/etc/hosts.deny}}} and {{{/etc/hosts.allow}}}.

If you have problems with remote access in a recent Debian system, comment out "ALL: PARANOID" in {{{/etc/hosts.deny}}} if it exists.

For details, see {{{inetd}}}(8), {{{inetd.conf}}}(5), {{{protocols}}}(5), {{{services}}}(5), {{{tcpd}}}(8), {{{hosts_access}}}(5), and {{{hosts_options}}}(5).

For more information on Sun-RPC, see {{{rpcinfo}}}(8), {{{portmap}}}(8), and {{{/usr/share/doc/portmap/portmapper.txt.gz}}}.

There are also non-PAM based access control available for {{{atd}}} and {{{cron}}}.

== Security of authentication ==

The information here may not be sufficient for your security needs but it should be a good start.

=== Secure password over the Internet ===

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 "[http://en.wikipedia.org/wiki/Transport_Layer_Security Transport Layer Security]" (TLS) or its predecessor, "Secure Sockets Layer" (SSL) to secure entire communication including password by the encryption.

|| List of insecure and secure services and ports. || || || ||
|| '''insecure service name''' || '''port''' || '''secure service name''' || '''port''' ||
|| www (http) || 80 || https || 443 ||
|| smtp (mail) || 25 || ssmtp (smtps) || 465 ||
|| ftp-data || 20 || ftps-data || 989 ||
|| ftp || 21 || ftps || 990 ||
|| telnet || 23 || telnets || 992 ||
|| imap2 || 143 || imaps || 993 ||
|| pop3 || 110 || pop3s || 995 ||
|| ldap || 389 || ldaps || 636 ||

The encryption costs CPU time.  As a CPU friendly alternative, you can keep communication in plain text while securing just 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.)

=== Secure Shell ===

The [http://en.wikipedia.org/wiki/Secure_Shell Secure Shell] ({{{ssh}}}) program ([http://www.openssh.org/ OpenSSH] SSH client) and {{{sshd}}} program (OpenSSH SSH daemon) provide secure encrypted communications between two untrusted hosts over an insecure network with the secure authentication.  This SSH can be used to tunnel the insecure protocol communication such as POP and X securely over the Internet with the port forwarding feature.

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 {{{man 1 ssh}}}, {{{man 8 sshd}}}, and @{@theremoteaccesssverandutilityssh@}@.

=== Extra security measures for the Internet ===

Even when you run secure services such as "Secure Shell" (SSH) and "Point-to-point tunneling protocol" (PPTP) 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 @{@netfilter@}@) together with the following secure tools may improve the security situation.

|| List of tools to provide extra security measures. || 1 || 2 ||
|| '''package''' || '''popcon''' || '''description''' ||
|| {{{knockd}}} || - || small port-knock daemon {{{knocked}}}(1) and client {{{konck}}}(1) ||
|| {{{denyhosts}}} || - || an utility to help sysadmins thwart ssh hackers ||
|| {{{fail2ban}}} || - || bans IPs that cause multiple authentication errors ||
|| {{{libpam-shield}}} || - || locks out remote attackers trying password guessing ||

## Unmaintained
## || {{{sshguard}}} || - || protects from brute force attacks against ssh ||

=== Securing the root password ===

To prevent people to access your machine with root privilege, you need to:

 * prevent physical access to the hard disk.
 * lock BIOS and prevent booting from the removable media.
 * set password for GRUB interactive session.
 * lock GRUB menu from editing.

With physical access to hard disk, resetting the password is relatively easy;

 * move the hard disk to a PC with CD bootable BIOS.
 * boot system with a rescue media (Debian boot disk, Knopix CD, GRUB CD, ...).
 * mount root partition with read-write access.
 * edit {{{/etc/passwd}}} in the root partition and make the second entry for {{{root}}} account empty.

If you have the edit access to the GRUB menu entry (see @{@stagecthebootloader@}@) for {{{grub-rescue-pc}}}) at the boot time, it is even easier:

 * boot system with the kernel parameter changed to something like "{{{root=/dev/hda6 rw init=/bin/sh}}}".
 * edit {{{/etc/passwd}}} and make the second entry for {{{root}}} account empty.
 * reboot system.

The root shell of the system is now accessible without password.

(!) Once you have root shell access, you can compromise password for all user accounts using brute force password cracking tools such as {{{john}}} and {{{crack}}} packages (see @{@systemsecurityandintegritycheck@}@).

The only reasonable software solution to avoid all these concerns is to use software encrypted root partition (or {{{/etc}}} partition) using [http://en.wikipedia.org/wiki/Dm-crypt dm-crypt] and initramfs (see @{@dataencryptiontips@}@).  You always need password to boot the system, though.