هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
usermod changes the account data in the user and group files. The most used job is adding a user to an extra group: usermod -aG GROUP USER.
Take care with -G: without -a it replaces all extra groups. A user who is logged in gets new groups only after a new login.
طريقة الكتابة
usermod [OPTION]... LOGINالخيارات 25
الأكثر استخدامًا
Groups
Account data
Home folder
Other
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 12
$ مستخدم عادي# بصلاحية root (أو مع sudo)
1Add a user to a group
usermod -aG webadmins lisalisa keeps all other groups.
2Give a user full sudo rights
usermod -aG wheel lisaOn RHEL wheel = all sudo rights.
3Block logins of a service account
usermod -s /sbin/nologin backup1The account can still own files and run jobs.
4Lock and unlock a password
usermod -L lisa usermod -U lisaA lock does not stop SSH key logins. Use an expire date too.
5Disable an account fully when someone leaves
usermod -L -e 1 olduser-e 1= expired on 2 Jan 1970: no login at all, also not with keys.6Move the home folder
usermod -d /srv/home/lisa -m lisa-m moves the files; without it only the entry changes.
7Rename a user
usermod -l lisa.hassan lisaThe home folder and group keep the old name; change them with -d -m and groupmod -n.
8Change the UID to match other servers
usermod -u 1501 sam find / -xdev -uid 1500 -exec chown -h sam {} +Files outside the home folder keep the old number; fix them with find.
9Remove one extra group
usermod -rG webadmins lisaOr use
gpasswd -d lisa webadmins(works on all versions).10Set an expire date
usermod -e 2026-12-31 contractor1Same as
chage -E 2026-12-31 contractor1.11Give a user ranges for rootless podman
usermod --add-subuids 100000-165535 --add-subgids 100000-165535 dev1Needed when the account was created without sub IDs.
12Check the result
id lisaShows all groups now.
لا يوجد شيء يطابق هذا الفلتر.
انتبه
usermod -G group userwithout-aremoves all other extra groups.- You cannot change the UID or name of a user who has running processes.
- New groups work only after a new login (or
newgrp).
الملفات
/etc/passwd, /etc/shadow, /etc/group, /etc/gshadow- The account files.
/etc/subuid, /etc/subgid- Sub ID ranges.
رموز الخروج
0 | Done. |
1 | Could not update the password file. |
2 | Wrong syntax. |
3 | Wrong value for an option. |
4 | UID already used. |
6 | The user or group does not exist. |
8 | The user is logged in (for changes that need logout). |
9 | The new name is already used. |
12 | Could not move the home folder. |