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: شناسه منحصربفرد گروه هر کاربر (دبیان به صورت پیش‌فرض برای هر کاربر یک گروه خاص قرار می‌دهد)؛
  • 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/passwd که شامل فیلدهای زیر است:
  • نام گروه؛
  • گذرواژه (اختیاری): این فیلد برای الحاق یک گروه استفاده می‌شود که یک عضو معمولی به حساب نمی‌آید (با دستورات newgrp یا sg، قسمت بازگشت به مقدمات کار با چندین گروه را مشاهده کنید)؛
  • gid: شناسه منحصربفرد هر گروه؛
  • فهرست اعضا: فهرستی از نام کاربرانی که عضو این گروه هستند، که با کاما جدا شده‌اند.
The addgroup and delgroup commands add or delete a group, respectively. The groupmod command modifies a group's information (its gid or identifier). The command gpasswd group changes the password for the group, while the gpasswd -r group command deletes it.