Linux基础命令:useradd

useradd [-d home] [-s shell] [-c comment] [-m [-k template]] [-f inactive] [-e expire ] [-p passwd] [-r] name

  • create a new user or update default new user information 创建用户

  • 注意一旦使用-s /sbin/nologin指定用户的bash为nologin,则代表该用户不能登陆系统

  • 常用选项

    -d:指定用户登入时的主目录,替换系统默认值/home/<用户名>
    -e:指定账号的失效日期,日期格式为MM/DD/YY,例如06/30/12。缺省表示永久有效
    -g:指定用户所属的群组。值可以使组名也可以是GID。用户组必须已经存在的,期默认值为100,即users
    -G:指定用户所属的附加群组
    -s:指定用户登入后所使用的shell。不指定即使用默认/bin/bash
    -u:指定用户ID号。该值在系统中必须是唯一的。0~999默认是保留给系统用户账号使用的,所以该值必须大于999(CentOS7)
    -m:自动建立用户的登入目录
    
  • 建立用户.并自动建立用户的登入目录.使用echo设置密码,不指定UID则系统自己指定.

    [root@centos7-test home]# ls
    xzt7566
    [root@centos7-test home]# useradd -m xzt123
    [root@centos7-test home]# echo "xxxxxx" | passwd --stdin  xzt123
    Changing password for user xzt123.
    passwd: all authentication tokens updated successfully.
    
    xzt7566:x:1000:1000:xzt7566:/home/xzt7566:/bin/bash
    xzt123:x:1001:1001::/home/xzt123:/bin/bash
    [root@centos7-test home]# ls
    xzt123  xzt7566
    
    [root@centos7-test home]# id xzt123
    uid=1001(xzt123) gid=1001(xzt123) groups=1001(xzt123)
    

你可能感兴趣的:(Linux基础命令:useradd)