Chinaunix首页 | 论坛 | 博客
  • 博客访问: 483346
  • 博文数量: 28
  • 博客积分: 858
  • 博客等级: 一等列兵
  • 技术积分: 852
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-02 14:13
文章分类

全部博文(28)

文章存档

2020年(1)

2019年(1)

2018年(5)

2017年(1)

2014年(1)

2013年(2)

2012年(17)

分类: LINUX

2012-05-21 13:42:36

    查看linux的man手册,我们知道useradd主要做以下几件事情。
update system files:
  1. /etc/passwd
  2. /etc/shadow
  3. /etc/group
  4. /etc/gshadow
create the new user's home directory
copy initial files
这里的initial files主要是/etc/skel目录下的文件。
关联文件:

点击(此处)折叠或打开

  1. /etc/default/useradd
  2. /etc/skel/
  3. /etc/login.defs

点击(此处)折叠或打开

  1. #/etc/default/useradd 这个目录主要是创建用户默认的一些参数设置
  2. # useradd defaults file
  3. GROUP=100
  4. HOME=/home
  5. INACTIVE=-1
  6. EXPIRE=
  7. SHELL=/bin/bash
  8. SKEL=/etc/skel
  9. CREATE_MAIL_SPOOL=yes

点击(此处)折叠或打开

  1. [root@node5 gsp]# ls -a /etc/skel/
  2. . .. .bash_logout .bash_profile .bashrc .emacs .mozilla .zshrc
这里就是需要拷贝的初始化文件。

点击(此处)折叠或打开

  1. MAIL_DIR /var/spool/mail
  2. PASS_MAX_DAYS 99999
  3. PASS_MIN_DAYS 0
  4. PASS_MIN_LEN 5
  5. PASS_WARN_AGE 7
  6. UID_MIN 500
  7. UID_MAX 60000
  8. GID_MIN 500
  9. GID_MAX 60000
  10. CREATE_HOME yes
  11. UMASK 077
  12. USERGROUPS_ENAB yes
  13. MD5_CRYPT_ENAB yes
这个主要是跟登陆相关的设置。

情景1:-c 添加comments

点击(此处)折叠或打开

  1. test:x:511:511:just a test:/home/test:/bin/bash

 点击(此处)折叠或打开

  1. [root@node5 gsp]# useradd -c 'just a test' test
  2. Creating mailbox file: File exists
  3. useradd: warning: the home directory already exists.
  4. Not copying any file from skel directory into it.
情景2:-d
指定用户的主目录也就是我们说的home dir,如果不指定将使用 HOME=/home ,也就是在home目录下创建以用户名为名字的文件夹作为home dir。

点击(此处)折叠或打开

  1. useradd -d /tmp/test/ test

点击(此处)折叠或打开

  1. [root@node5 gsp]# ll /home/
  2. total 48
  3. drwx------ 4 chennan ftpgroup 4096 Mar 29 04:16 chennan
  4. drwxr-xr-x 2 root root 4096 Feb 28 16:01 client
  5. drwx------ 3 ipython ipython 4096 Sep 25 2011 com
  6. drwx------ 3 507 507 4096 Sep 25 2011 com1
  7. drwx------ 3 ftp_repository ftpgroup 4096 May 26 2011 ftp_repository
  8. drwx------ 5 ipython ipython 4096 Sep 28 2011 ipython
  9. drwx------ 6 moon moon 4096 Dec 17 06:09 moon
  10. drwx------ 3 piduser piduser 4096 Feb 26 19:59 piduser
  11. drwx------ 3 service service 4096 May 26 2011 service
  12. drwx------ 3 smb_sis smbgroup 4096 Sep 23 2011 smb_sis

点击(此处)折叠或打开

  1. [root@node5 gsp]# ll /tmp/
  2. total 16
  3. drwxr-xr-x 8 root root 4096 May 17 18:00 drbd-8.3.11
  4. drwxr-xr-x 3 root root 4096 Jul 9 2011 gsp
  5. drwxr-xr-x 3 root root 4096 Sep 26 2011 iso
  6. drwx------ 3 test test 4096 May 21 13:48 test
情景3:-p
指定密码,这里的密码是加密后的。如果不指定,刚开始的用户是不能使用的。
情景4:-s
指定所使用的shell,如果不指定将使用/etc/default/useradd中的SHELL=/bin/bash
情景5:-G
指定用户组。
使用useradd -G piduser test之后/etc/group 文件发生变化。

点击(此处)折叠或打开

  1. piduser:x:509:com,test
取消情景:删除用户

点击(此处)折叠或打开

  1. userdel -f -r test
这里的意思连同创建的家目录一同删除。
阅读(5969) | 评论(0) | 转发(0) |
0

上一篇:Linux login 过程浅析

下一篇:随感

给主人留下些什么吧!~~