useradd用于Linux中创建系统用户,useradd创建好账号后,需要使用passwd为账号设置密码;同样,也可以使用userdel命令删除系统用户。
useradd创建的用户信息保存的/etc/passwd文本中。
useradd用法是 useradd (选项) (参数)
具体的选项:
-
-b, --base-dir BASE_DIR base directory for the home directory of the new account
-
-c, --comment COMMENT GECOS field of the new account # 设置备注
-
-d, --home-dir HOME_DIR home directory of the new account # 指定HOME_DIR ,默认的/home/username,我们可以设置为/home/t1等
-
-D, --defaults print or change default useradd configuration #
-
-e, --expiredate EXPIRE_DATE expiration date of the new account #设置过期时间
-
-f, --inactive INACTIVE password inactivity period of the new account #指定在密码过期后多少天即关闭该帐号
-
-g, --gid GROUP name or ID of the primary group of the new account #设置账号的所属群组
-
-G, --groups GROUPS list of supplementary groups of the new account #设置账号的附属所属群组
-
-h, --help display this help message and exit
-
-k, --skel SKEL_DIR use this alternative skeleton directory
-
-K, --key KEY=VALUE override /etc/login.defs defaults
-
-l, --no-log-init do not add the user to the lastlog and faillog databases
-
-m, --create-home create the user's home directory #创建账号的家目录
-
-M, --no-create-home do not create the user's home directory #不创建以账号命名的家目录
-
-N, --no-user-group do not create a group with the same name as the user #不创建以账号命名的群组
-
-o, --non-unique allow to create users with duplicate (non-unique) UID
-
-p, --password PASSWORD encrypted password of the new account
-
-r, --system create a system account
-
-R, --root CHROOT_DIR directory to chroot into
-
-s, --shell SHELL login shell of the new account #设置账号的shell
-
-u, --uid UID user ID of the new account #设置账号的UID值
-
-U, --user-group create a group with the same name as the user
-
-Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping
实例:新创建用户inds3,设置UID 1501,家目录为/home/inds003 ,密码有效期30天 ,不创建以账号命名的群组
-
[root@localhost ~]# useradd -u 1501 -d /home/inds003 -e 30 -N inds3
-
[root@localhost ~]#
-
[root@localhost ~]#
-
[root@localhost ~]# id inds3
-
uid=1501(inds3) gid=100(users) groups=100(users)
-
[root@localhost ~]# su - inds3
-
[inds3@localhost ~]$ pwd
-
/home/inds003
-
[inds3@localhost ~]$ grep inds3 /etc/passwd
-
inds3:x:1501:100::/home/inds003:/bin/bash
-
[root@localhost ~]# grep inds3 /etc/shadow
-
inds3:!!:16918:0:99999:7::30:
-
[root@localhost ~]#
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27039319/viewspace-2089268/
,如需转载,请注明出处,否则将追究法律责任。