Product SiteDocumentation Site

8.4. ユーザとグループのデータベース

The list of users is usually stored in the /etc/passwd file, while the /etc/shadow file stores hashed passwords. Both are text files, in a relatively simple format, which can be read and modified with a text editor. Each user is listed there on a line with several fields separated with a colon (“:”).

8.4.1. ユーザリスト、/etc/passwd

以下は /etc/passwd ファイルに含まれるフィールドのリストです。
  • ログイン名。これはたとえば rhertzog です。
  • password: this is a password encrypted by a one-way function (crypt), relying on DES, MD5, SHA-256 or SHA-512. The special value “x” indicates that the encrypted password is stored in /etc/shadow;
  • uid。これは各ユーザを識別する一意的な番号です。
  • gid。これはユーザのメイングループを示す一意的な番号です (Debian はデフォルトで各ユーザに固有のグループを作成します)。
  • GECOS。通常これはユーザの氏名を含むデータフィールドです。
  • ログインディレクトリ。これはユーザが個人ファイルを保存するために割り当てられたディレクトリです (環境変数 $HOME は通常このディレクトリを指します)。
  • ログイン時に実行されるプログラム。通常これはユーザに行動の自由を与えるコマンドインタプリタ (シェル) です。/bin/false (何もせずすぐにコントロールを返すプログラム) が指定された場合、ユーザはログインできません。
As mentioned before, one can edit this file directly. But there are more elegant ways to apply changes, which are described in 第 8.4.3 節「既存のアカウントやパスワードの変更」.

8.4.2. 隠された暗号化パスワードファイル、/etc/shadow

/etc/shadow ファイルには以下のフィールドが含まれます。
  • ログイン名。
  • 暗号化されたパスワード。
  • パスワードの有効期限を管理するいくつかのフィールド。
One can expire passwords using this file or set the time until the account is disabled after the password has expired.

8.4.3. 既存のアカウントやパスワードの変更

The following commands allow modification of the information stored in specific fields of the user databases: passwd permits a regular user to change their password, which in turn, updates the /etc/shadow file (chpasswd allows administrators to update passwords for a list of users in batch mode); chfn (CHange Full Name), reserved for the super-user (root), modifies the GECOS field. chsh (CHange SHell) allows the user to change their login shell; however, available choices will be limited to those listed in /etc/shells; the administrator, on the other hand, is not bound by this restriction and can set the shell to any program of their choosing.
最後に、chage (CHange AGE) コマンドを使うと、管理者はパスワードの有効期限設定を変更できます (-l user オプションで現在の設定を表示します)。passwd -e user コマンドを使うと、パスワードを強制的に失効させることが可能です。ユーザは次回のログイン時にパスワード変更を要求されます。
Besides these tools the usermod command allows to modify all the details mentioned above.

8.4.4. アカウントの失効

You may find yourself needing to “disable an account” (lock out a user), as a disciplinary measure, for the purposes of an investigation, or simply in the event of a prolonged or definitive absence of a user. A disabled account means the user cannot login or gain access to the machine. The account remains intact on the machine and no files or data are deleted; it is simply inaccessible. This is accomplished by using the command passwd -l user (lock). Re-enabling the account is done in similar fashion, with the -u option (unlock). This, however, only prevents password-based logins by the user. The user might still be able to access the system using an SSH key (if configured). To prevent even this possibility you have to expire the account as well using either chage -E 1user or usermod -e 1 user (giving a value of -1 in either of these commands will reset the expiration date to never). To (temporarily) disable all user accounts just create the file /etc/nologin.
You can disable a user account not only by locking it as described above, but also by changing its default login shell (chsh -s shell user). With the latter changed to /usr/sbin/nologin, a user gets a polite message informing that a login is not possible, while /bin/false just exits while returning false. There is no switch to restore the previous shell. You have to get and keep that information before you change the setting. These shells are often used for system users which do not require any login availability.

8.4.5. グループリスト、/etc/group

グループは /etc/group ファイルにリストされています。/etc/group ファイルは単純なテキストデータベースで、フォーマットは /etc/passwd ファイルとよく似ており、以下のフィールドを持っています。
  • グループ名。
  • パスワード (任意)。これはグループメンバーでないユーザがそのグループに参加する際に使われます (newgrp および sg コマンドを使います。補注BACK TO BASICS 複数のグループに所属する」を参照してください)。
  • gid。これはグループを識別する一意的な番号です。
  • メンバーのリスト。これはグループに所属するユーザ名のコンマ区切りリストです。
addgroup コマンドはグループを追加、delgroup コマンドはグループを削除します。groupmod コマンドは指定したグループの情報 (gid またはグループ名など) を変更します。gpasswd groupgroup で指定したグループのパスワードを変更し、一方で gpasswd -r group コマンドは group で指定したグループを削除します。