هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
useradd writes the new account to /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow. On RHEL it also creates a group with the same name and a home folder in /home, with a copy of the files in /etc/skel.
The new account has no password yet, so nobody can log in with it. Set one with passwd.
Values you do not give come from /etc/login.defs (UID range, password aging, home mode) and /etc/default/useradd (shell, home base, skel). useradd -D shows and changes the second file.
طريقة الكتابة
useradd [OPTION]... LOGIN
useradd -D
useradd -D [-b BASE] [-e DATE] [-f DAYS] [-g GROUP] [-s SHELL]الخيارات 26
الأكثر استخدامًا
Account data
Groups
Home folder
Other
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 11
$ مستخدم عادي# بصلاحية root (أو مع sudo)
1Create a user with a full name
useradd -c "Lisa Hassan" lisa passwd lisaWithout a password nobody can log in.
2Create a user with extra groups
useradd -G wheel,webadmins omar id omar uid=1002(omar) gid=1002(omar) groups=1002(omar),10(wheel),1100(webadmins)The groups must exist.
3Choose the UID
useradd -u 1500 samSame UID on all servers keeps NFS file owners right.
4Create a service account
useradd -r -s /sbin/nologin -d /var/lib/myapp -M myappNo login shell, no home, UID under 1000 (least privilege for an app).
5Create a temporary account that expires
useradd -e 2026-12-31 -c "Contractor" contractor1After this date the account cannot log in.
6Show the defaults
useradd -D GROUP=100 HOME=/home INACTIVE=-1 EXPIRE= SHELL=/bin/bash SKEL=/etc/skelThese values come from /etc/default/useradd.
7Change the default shell for new users
useradd -D -s /bin/zshOnly new users get it.
8Use another start folder for a team
useradd -m -k /etc/skel-dev dev1Developers get their own .bashrc and tools config.
9Map a user to a confined SELinux user
useradd -Z staff_u admin2A confined admin cannot do everything even as root (hardening).
10Create many users from a list
Only for labs: real users need a good password each.
11Check the new account
The home folder has the files from /etc/skel.
لا يوجد شيء يطابق هذا الفلتر.
انتبه
useradddoes not set a password. Usepasswdafter it.-pwants a hash, not the password text.useradd -p secretgives an account that cannot log in.- Changes in /etc/skel or login.defs only affect new users.
الملفات
/etc/passwd, /etc/shadow- Account and password data.
/etc/group, /etc/gshadow- Group data.
/etc/login.defs- UID/GID ranges, password aging, home mode, umask.
/etc/default/useradd- Defaults for shell, home base and skel.
/etc/skel/- Start files for new home folders.
رموز الخروج
0 :: Done. 1 :: Could not update the password file. 2 :: Wrong syntax. 3 :: Wrong value for an option. 4 :: UID already used. 6 :: The group does not exist. 9 :: The user name is already used. 12 :: Could not create the home folder. 14 :: Could not update the SELinux user mapping.