�����û�������useradd��adduser ���������������ﵽ��Ŀ�Ķ���һ���ģ���Fedora ���а���,useradd ��adduser �÷���һ���ģ�����slackware���а汾�У�adduser��useradd ����������ͬ������Ϊadduser �����˻����������ʵķ�ʽ�������û���
����useradd��adduser�������⣬���ǻ���ͨ�����û������ļ�/etc/passwd��/etc/groups�İ취��ʵ�֣�
��Ȼ����Ҳ��Ҫ����һЩ���а������û��������ߣ�����Fedora ���� system-config-users ���ߣ��������߱Ƚϼ��㼸�������������ɣ�
1��useradd ����
useradd ���Ӳ���ѡ��ʱ������ֱ�Ӹ������ӵ��û���ʱ��ϵͳʱ��ȡ�����û������ļ�/etc/login.defs��/etc/default/useradd�� ����Ȼ����ȡ/etc/login.defs��/etc/default/useradd���������Ĺ��������û�������/etc/passwd�� /etc/groups�ļ������û����û�����¼����Ȼ/etc/passwd��/etc/groups�ļ�����Ѷ�ļ�Ҳͬ�����ɼ�¼��ͬʱ�����Ļ���ϵ ͳ���Զ���/etc/add/default����Լ����Ŀ¼�н��û��ļ�Ŀ¼��������/etc/skel�е��ļ������������ļ��������û��ļ�Ŀ¼�У�
useradd �����
usage: useradd [-u uid [-o]] [-g group] [-G group,...]
[-d home] [-s shell] [-c comment] [-m [-k template]]
[-f inactive] [-e expire ] [-p passwd] name
useradd -D [-g group] [-b base] [-s shell]
[-f inactive] [-e expire ]
������ִ��useradd �û��� �������û�ʱ�����ǻᷢ��һ���Ƚ�����˼�������������е��û��ļ�Ŀ¼���DZ��Զ����ӵ� /homeĿ¼�£������Ⱦٸ����ӣ�
ʵ��һ�������κβ�����ֱ�������û���
[root@localhost beinan]# useradd beinanlinux
[root@localhost beinan]# ls -ld /home/beinanlinux/
drwxr-xr-x 3 beinanlinux beinanlinux 4096 11�� 2 15:20 /home/beinanlinux/
�����������У�����������beinanlinux�û��������ڲ鿴/home/Ŀ¼ʱ���ᷢ��ϵͳ�Խ���һ��beinanlinux��Ŀ¼��
���������鿴 /etc/passwd �ļ��й�beinanlinux�ļ�¼��Ҳ�����·��֣�����ͨ��more ����ȡ /etc/passwd �ļ�������ͨ��grep ����ȡ beinanlinux�ֶΣ��ó�����һ�У�
[root@localhost beinan]# more /etc/passwd | grep beinanlinux
beinanlinux:x:509:509::/home/beinanlinux:/bin/bash
�ӵó���beinanlinux�ļ�¼��������adduser ��������beinanlinux�û�ʱ�������û���UID��GID�ֱ�Ϊ509 �����Ұ�beinanlinux�ļ�Ŀ¼������ /home/beinanlinux �����е�SHELL�� bash �� ������������ /etc/shadow��/etc/groups��/etc/gshadow �ļ����Dz���Ҳ����beinanlinux�йص��У����ǻ�Ҫ�鿴/etc/default/useradd ��/etc/login.defs�ļ��Ĺ���һ��beinanlinux�û��������Dz��Ǻ������������ļ��йأ����ǻ�Ҫ�鿴 /home/beinanlinuxĿ¼�µ��ļ����Dz��Ǻ�/etc/skelĿ¼�е�һ����
�ɴ�������������������Ҫ̸�����ݣ�
useradd -D [-g group] [-b base] [-s shell] [-f inactive] [-e expire ]
1��/etc/default/useradd �����ļ��Ķ��壻
useradd -D [-g group] [-b base] [-s shell] [-f inactive] [-e expire ]
useradd ��-D�������������ı������ļ� /etc/default/useradd�ģ�
useradd -D [-g group] [-b base] [-s shell] [-f inactive] [-e expire ]
��-Dѡ������ʱ��useradd�������ڵ�Ԥ��ֵ�����ǽ��������еķ�ʽ����Ԥ��ֵ������ѡ��Ϊ��
-b default_home ע�������û�����Ŀ¼��ǰһ��Ŀ¼���û����ƻḽ����default_home���������������û���Ŀ¼����Ȼʹ��-d������ѡ����Ч��
-e default_expire_date ע���û��ʺ�ֹͣ���ڡ�
-f default_inactive ע���ʺŹ��ڼ��պ�ͣȨ��
-g default_group ע�����ʺ���ʼ�û�������ID���û�������Ϊ���д��ڵ����ơ��û���IDҲ��Ϊ���д��ڵ��û��顣
-s default_shell ע���û�������ʹ�õ�shell���ơ������¼������ʺŶ���ʹ�ô�shell.
�粻ָ���κβ�����useradd��ʾĿǰԤ����ֵ��
ʵ������
useradd -D �粻ָ���κβ�����useradd��ʾĿǰԤ����ֵ��
[root@localhost beinan]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=no
���ǿ�һ��/etc/default/useradd �ļ��������ˣ�Ӧ�ú�������������һ���ģ����������������ı�useradd�����ļ�/etc/default/adduser �����ݣ�Ҳ�����ñ༭��ֱ�Ӳ���������������vi�༭�����������༭���Ļ�������Ӧ�ò��������ɣ�
ʵ������
�����������û�ʱ��Ĭ��SHELL /bin/bash ��Ϊ /bin/tcsh ����Ӧ�������������
[root@localhost beinan]# useradd -D -s /bin/tcsh ע���������û�ʱ��SHELL ��Ϊtcsh ��
[root@localhost beinan]# more /etc/default/useradd ע���鿴�Ƿ��ɹ���
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/tcsh ע���ɹ���
SKEL=/etc/skel
CREATE_MAIL_SPOOL=no
����-D�����Ľ�˵�������ˣ�Ҳ�DZȽϼ��������������ֱ�ӸIJ��������ļ��ܻ��ɣ�Linux���������Ǽ�Ϊ�����ģ��Ϳ�������ô�����ˣ��Բ��ԣ�
2��useradd �����û���
useradd [-u uid [-o]] [-g group] [-G group,...]
[-d home] [-s shell] [-c comment] [-m [-k template]]
[-f inactive] [-e expire ] [-p passwd] name
���ʺŽ�����������-D����,useraddָ��ʹ����������ָ�����ʺŵ��趨ֵ andʹ��ϵͳ�ϵ�Ԥ��ֵ.���û��ʺŽ�����һЩϵͳ�������û�Ŀ¼������������ʼ�����ȣ���Щ����������������ѡ��ָ�����˰汾ΪRedHat Linux�ṩ���ɰ�ÿ���¼������û�����������group,��������-nѡ�
useradd ��ʹ�õ�ѡ��Ϊ
-c comment ע�����ʺ� password ����˵���� ��
-d home_dir ע�����ʺ�ÿ�ε���ʱ��ʹ�õ�home_dir��Ԥ��ֵΪdefault_home��login���ƣ������ɵ���ʱĿ¼���ơ�
-e expire_date ע���ʺ���ֹ���ڡ����ڵ�ָ����ʽΪMM/DD/YY��
-f inactive_days ע���ʺŹ��ڼ��պ�����ͣȨ����ֵΪ0ʱ�ʺ������̱�ͣȨ������ֵΪ-1ʱ���رմ˹��ܣ�Ԥ��ֵΪ-1
-g initial_group ע��group���ƻ�����������Ϊ�û�������ʼ�û���(group)���û�������Ϊ���д��ڵ����ơ��û�������Ҳ��Ϊ���д��ڵ��û��顣Ԥ�����û�������Ϊ1��
-G group,[...]
ע���������û�Ϊ��һ��groups�ij�Ա��ÿ���û���ʹ��","���������������Լ��ӿհ���Ԫ���û�����ͬ-gѡ�������ơ�����ֵΪ�û�����ʼ�û��顣��
-m ע���û�Ŀ¼�粻�������Զ���������ʹ��-kѡ��skeleton_dir�ڵĵ������������û�Ŀ¼�¡�Ȼ����/etc/skelĿ¼�µĵ���Ҳ�Ḵ�ƹ� ȥȡ�����κ���skeleton_dir or /etc/skel��Ŀ¼Ҳ��ͬ�����û�Ŀ¼��һһ������The-kͬ-m������Ŀ¼�Լ��������κε���ΪԤ��ֵ��
-M �������û�Ŀ¼����ʹ/etc/login.defsϵͳ���趨Ҫ�����û�Ŀ¼��
-n Ԥ��ֵ�û��û������û����ƻ���ͬ����ѡ�ȡ����Ԥ��ֵ��
-r �˲�������������ϵͳ�ʺš�ϵͳ�ʺŵ�UID���ȶ�����ϵͳ����/etc/login.defs.��UID_MIN����С��ע��useradd���÷����� �����ʺŲ��Ὠ���û�Ŀ¼��Ҳ�����ں���¼��/etc/login.defs.�Ķ���ֵ����������Ҫ���û�Ŀ¼������ָ��-m����������ϵͳ�ʺš�
-s shell ע���û�������ʹ�õ�shell���ơ�Ԥ��Ϊ����д������ϵͳ������ָ��Ԥ���ĵ���shell��
-u uid uid�û���IDֵ������ΪΨһ��IDֵ��������-oѡ����ֲ���Ϊ��ֵ��Ԥ��Ϊ��/etc/login.defs�е�UID_MIN��ֵΪ��0��UID_MIN��ֵ֮�䣬Ϊϵͳ������UID ��
useradd ��ô���IJ�������ȥͷ�е��Σ������������أ�����ʵ�ܼ�һ������һ����������һ�Բ��������ˣ����������õ�ѧϰ������ʵ���Ǽ���������Ψһ����
����useradd ����ֱ�Ӹ��û����������κβ�������ʾ�����û�ʱ������/etc/default/adduser ��/etc/login.defs �������û��������ļ��Ĺ����������û�����ʵ����Ϊ�˷��㣬Ҳ�����������ļ������ʺ����������û���Ҫ��
[NextPage]
useradd Ϊʲô����Ҫ��ô���IJ����أ�
ԭ���ܼ���Ҫ��Ϊ�˹���Ա���������û���useradd �������ģ���������/dev/default/adduser ��/etc/login.defs ���������ļ��еĹ������Զ��������û����������û��ļ�Ŀ¼����/etc/default/adduser �п��ܶ�����/homeĿ¼�½������������ǵĻ���/home����ռһ�������������е����ţ��������ֲ����ı�/etc/default/adduser ���ڼ�Ŀ¼�Ķ��壬�������ǾͿ���ͨ�� adduser -d �����������û���Ŀ¼���嵽�ռ��ȽϿձյķ�����
ͨ�������ļ������ӣ�������������������useradd ����ʵ�ܼ���~��ѧϰҲ���������ȴӼ����֣�һ��һ�����߹�����û��ʲô�ѵ�~~
ʵ���ģ���/etc/logins.defs��/etc/default/adduser Ĭ�ϵĹ��������û���
[root@localhost ~]# useradd longcpu
ע�⣺����useradd ����ֱ���û�������ʾϵͳ��ȡ /etc/login.defs��/etc/default/adduser �����ļ������������������ļ��������Ĺ����������û��������û��ļ�Ŀ¼�����ʲôSHELL��UID��GID�ķ���... ... �鿴/etc/passwd��������¼��Ȼ������ /etc/login.defs��/etc/default/adduser �鿴�����û��Ƿ����������������ļ���Լ���Ĺ�����
ʵ���壺��ϰ������ʹ�ã�
[root@localhost ~]# useradd -c ChinaCpu longcpu ע������һ�����û�amdcpu ��ʹ�ò���-c��
[root@localhost ~]# more /etc/passwd |grep longcpu ע���鿴/etc/passwd �ļ�������ȡlongcpu�ļ�¼��
longcpu:x:510:510:ChinaCpu:/home/longcpu:/bin/bash
ע������ȥ���Ѿ���amdcpu�û��ˣ�x�������Σ�UID��GID ����510��ChinaCpu��ʾ��ʲô��˼�� ��Ŀ¼λ��/home/amdcpu��SHELL��bash ��
[root@localhost ~]# finger longcpu ע�����Dz�ѯһ��amdcpu �û�����Ϣ��
Login: longcpu Name: ChinaCpu ע��-c ChinaCpu ��ʾ�û���ʵ�����ֻ�ȫ����
Directory: /home/longcpu Shell: /bin/bash
Never logged in.
No mail.
No Plan.
ע�⣺�������ӣ��������������û����鿴/etc/passwd �ı仯�� ����ͨ��finger ����ѯlongcpu�û�����Ϣ��Ŀ������������-c���ô���
����-c �����ľ��Ǿ���UID:GID����˵�����֣����������а����û���ʵ�������칫��ַ���칫�绰�ȣ�����ͨ��chfn �����ģ����ǿ���ͨ��chfn �����û���Ϣ��Ȼ���鿴 /etc/passwd �ı仯��������finger ����ѯ�û���Ϣ����������������ϰһ�£�Ҳ�������ǣ�
ʵ�������Զ����û��ļ�Ŀ¼��SHELL���͡����������û����ȣ�
�����û�longcpu�����������û���ʵ����ΪChinaCpu������Ŀ¼��/opt/longcpu����������Ϊ�û��� linuxsir��root��beinan��Ա����SHELL����Ϊtcsh ��
[root@localhost ~]# useradd -c ChinaCpu -d /opt/longcpu -G linuxsir,root,beinan -s /bin/tcsh longcpu
ע�������û�longcpu ����ʵ����ChinaCpu ����Ŀ¼������ /opt/longcpu ����linuxsir,root,beinan �û�����Ա�� SHELL��tcsh ��
[root@localhost ~]# ls -ld /opt/longcpu/ ע���Dz����Զ�������longcpu�ļ�Ŀ¼��
drwxr-xr-x 3 longcpu longcpu 4096 11�� 4 22:30 /opt/longcpu/
[root@localhost ~]# more /etc/passwd |grep longcpu ע���鿴 /etc/passwd ���Ƿ���longcpu�û���¼��
longcpu:x:510:510:ChinaCpu:/opt/longcpu:/bin/tcsh
[root@localhost beinan]# finger longcpu ע����ѯlongcpu�û�����Ϣ ��
Login: longcpu Name: ChinaCpu
Directory: /opt/longcpu Shell: /bin/tcsh
Never logged in.
No mail.
No Plan.
[root@localhost beinan]# id longcpu ע����ѯUID��GID �Լ����������û��飻
uid=510(longcpu) gid=510(longcpu) groups=510(longcpu),0(root),500(beinan),502(linuxsir)
�������������û�ʱ�û��飬�����û�ʱ��������ʹ��-n ������ϵͳ���Զ���һ�����û���ͬ�����û��飻
ʵ���ߣ���ϰ�û���Ч���ޣ�
�ڱ����У�������Ҫ������-e�����������������DZȽ���Ҫ�ģ����趨�û����ʺ�ʲôʱ�����ڣ�
�ڱ����У�����������һ���ʺţ������������ʺ��� 2005��11��04��֮ǰ����Ч�ģ�һ�������������ڣ���ֹͣ����¼��
[root@localhost ~]# useradd -e 11/04/2005 cooler ע�������û�cooler������������Ч��Ϊ2005��11��04�գ�
[root@localhost ~]# passwd cooler ע�������û�cooler���룻
Changing password for user cooler.
New UNIX password: ע���趨cooler�����룻
Retype new UNIX password: ע����ʵ�趨���룻
passwd: all authentication tokens updated successfully. ע�����óɹ���
������֤-e �Dz���������Ч����д��ƪ�ĵ���ʱ���� 2005��11��05�ţ�������������cooler�û��϶��ǹ��ڵģ�������������Ҳ���ܵ�¼��
�еĵ��ֻ��ʣ�������Ч�ڵļ�¼�����������أ���ʵ��������ǰ���ĵ����Ѿ�˵���ˣ���д��/etc/shadow�ļ����ˣ�
���ο��� ���û���user�����û��飨group�������ļ����⡷
2��adduser ���ߣ�
��Fedora ϵͳ�У�adduser��useradd �÷���һ���ģ����� Slackware ϵͳ�� adduser ��ͨ���˻������ķ����������û�����ʵ��useradd �Ӹ����������Զ��������û����ﵽ��Ŀ����һ���ģ�ֻ������Slackware �У�useradd �����˻�����������ʽ�Ľ��У���������û�б�Ҫ֪����ô���IJ�����һ�����Դﵽ�Զ��������û���
[root@localhost ~]# adduser ע������adduser���
Login name for new user []: bluemoon ע���������û� bluemoon
User ID ('UID') [ defaults to next available ]: 1200 ע���û���UID ��UID ��Ψһ�ģ���������ʾ˵��ռ�ã���ѡ�Ƚϴ���UID ������1300
Initial group [ users ]: users ע����ʼ���û��飨�����û��飩Ϊusers�������û���Ҳ�ǿ����Լ������ģ����û����������ڣ����������ڣ���������groupadd������
Additional groups (comma separated) []: root,beinan ע�������û��飬����Ҳ���Լ������ģ������û���֮����,�ŷָ
Home directory [ /home/bluemoon ] ע�������û��ļ�Ŀ¼λ�ã�Ҳ�ǿ����Լ������ģ�����/opt/bluemoon ��
Shell [ /bin/bash ] ע������SHELL ���˴��õ���bash ��
Expiry date (YYYY-MM-DD) []: ע���û�����Ч���ڣ����������þ�ֱ�ӻس�����ʾ�Ӳ����ڣ��������þ���2005-11-05�����ĸ�ʽ�����룻
New account will be created as follows: ע���������û��������£�
---------------------------------------
Login name.......: bluemoon
UID..............: 1200
Initial group....: users
Additional groups: root
Home directory...: /home/bluemoon
Shell............: /bin/bash
Expiry date......: [ Never ]
This is it... if you want to bail out, hit Control-C. Otherwise, press
ENTER to go ahead and make the account.
ע�������ﰴ�س��Ϳ�ʼ������������Ϊ�������������Ͱ�CTRL+C ���жϣ�
Creating new account... �����ʹ������ˣ�ϵͳ���Զ���ʾ�������û�����Ϣ�������û���ȫ���������š��绰��...... �Լ��û������룻
Changing the user information for bluemoon
Enter the new value, or press ENTER for the default
Full Name []: bluemoon Linux
Room Number []: 503
Work Phone []: 0411-8888888
Home Phone []: 0411-9999999
Other []:
Changing password for bluemoon
Enter the new password (minimum of 5, maximum of 127 characters)
Please use a combination of upper and lower case letters and numbers.
New password: ע�������û�bluemoon�����룻
Re-enter new password: ע����֤һ�Σ�
Password changed. ע�����������ɹ�
�˽���Щ�֣��͵���˼ ������˼ �ӵ���˼ �õ���˼ ������˼ ������˼ �ߵ���˼ ʹ����˼