linux 基础命令useradd

useradd用于Linux中创建系统用户,useradd创建好账号后,需要使用passwd为账号设置密码;同样,也可以使用userdel命令删除系统用户。
useradd创建的用户信息保存的/etc/passwd文本中。

useradd用法是 useradd  (选项) (参数)
具体的选项:

点击(此处)折叠或打开

  1. -b, --base-dir BASE_DIR base directory for the home directory of the new account
  2. -c, --comment COMMENT GECOS field of the new account       # 设置备注
  3. -d, --home-dir HOME_DIR home directory of the new account  # 指定HOME_DIR ,默认的/home/username,我们可以设置为/home/t1等
  4. -D, --defaults print or change default useradd configuration   #
  5. -e, --expiredate EXPIRE_DATE expiration date of the new account   #设置过期时间
  6. -f, --inactive INACTIVE password inactivity period of the new account   #指定在密码过期后多少天即关闭该帐号
  7. -g, --gid GROUP name or ID of the primary group of the new account   #设置账号的所属群组
  8. -G, --groups GROUPS list of supplementary groups of the new account  #设置账号的附属所属群组
  9. -h, --help display this help message and exit
  10. -k, --skel SKEL_DIR use this alternative skeleton directory
  11. -K, --key KEY=VALUE override /etc/login.defs defaults
  12. -l, --no-log-init do not add the user to the lastlog and faillog databases 
  13. -m, --create-home create the user's home directory              #创建账号的家目录
  14. -M, --no-create-home do not create the user's home directory               #不创建以账号命名的家目录
  15. -N, --no-user-group do not create a group with the same name as the user   #不创建以账号命名的群组
  16. -o, --non-unique allow to create users with duplicate (non-unique) UID
  17. -p, --password PASSWORD encrypted password of the new account
  18. -r, --system create a system account                          
  19. -R, --root CHROOT_DIR directory to chroot into
  20. -s, --shell SHELL login shell of the new account                #设置账号的shell
  21. -u, --uid UID user ID of the new account                        #设置账号的UID值
  22. -U, --user-group create a group with the same name as the user
  23. -Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping
实例:新创建用户inds3,设置UID 1501,家目录为/home/inds003 ,密码有效期30天 ,不创建以账号命名的群组

点击(此处)折叠或打开

  1. [root@localhost ~]# useradd -u 1501 -d /home/inds003 -e 30 -N inds3
  2. [root@localhost ~]#
  3. [root@localhost ~]#
  4. [root@localhost ~]# id inds3
  5. uid=1501(inds3) gid=100(users) groups=100(users)
  6. [root@localhost ~]# su - inds3
  7. [inds3@localhost ~]$ pwd
  8. /home/inds003
  9. [inds3@localhost ~]$ grep inds3 /etc/passwd
  10. inds3:x:1501:100::/home/inds003:/bin/bash
  11. [root@localhost ~]# grep inds3 /etc/shadow
  12. inds3:!!:16918:0:99999:7::30:
  13. [root@localhost ~]#


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27039319/viewspace-2089268/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27039319/viewspace-2089268/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值