1.创建用户命令 useradd详解
今天新学了useadd 创建用户的命令,小小的总结一下
useradd创建用户的命令
[root@oldboy ~]# useradd oldboy
[root@oldboy ~]# tail -1 /etc/passwd
oldboy:x:500:500::/home/oldboy:/bin/bash
useradd -e设定用户的过期时间
[root@oldboy ~]# useradd -e '2015/08/19'oldboy1
[root@oldboy ~]# chage -l oldboy1
Last password change : Aug 19,2014
Password expires : never
Password inactive : never
Account expires : Aug19, 2015
Minimum number of days between passwordchange : 0
Maximum number of days between passwordchange : 99999
Number of days of warning before passwordexpires : 7
useradd -u设置UID
[root@oldboy ~]# useradd -u 801 oldboy2
[root@oldboy ~]# tail -1 /etc/passwd
oldboy2:x:801:1001::/home/oldboy2:/bin/bash
useradd -g指定用户所属的组(不需要事后修改)
[root@oldboy ~]# groupadd huang
[root@oldboy ~]# tail -1 /etc/group
huang:x:1002:
[root@oldboy ~]# useradd -g huang oldboy3
[root@oldboy ~]# id oldboy3
uid=803(oldboy3) gid=1002(huang) groups=1002(huang)
useradd -d指定用户的主目录(家目录)如果目录不存在可以同时用-m 来创建这个目录
[root@oldboy ~]# useradd -d /tmp/huang -moldboy4
[root@oldboy ~]# tail -1 /etc/passwd
oldboy4:x:804:804::/tmp/huang:/bin/bash
useradd -G指定用户所属的附加组(一个用户可以有多个组)
[root@oldboy ~]# groupadd huang1
[root@oldboy ~]# tail -2 /etc/group
oldboy4:x:804:
huang1:x:1003:
[root@oldboy ~]# useradd -G huang1,oldboy4oldboy5
[root@oldboy ~]# id oldboy5
uid=805(oldboy5) gid=805(oldboy5) groups=805(oldboy5),804(oldboy4),1003(huang1)
useradd -s指定用户登录shell 可以禁止登录
useradd -s /sbin/nologin oldboy6
[root@oldboy ~]# tail -1 /etc/passwd
oldboy6:x:806:806::/home/oldboy6:/sbin/nologin
以上参数皆可以组合使用:
useradd -u 855 -g huang -d /tmp/huang1 -m-e "2015/08/19" -s /sbin/nologin oldboy7
[root@oldboy ~]# chage -l oldboy7
Last password change : Aug 19,2014
Password expires : never
Password inactive : never
Account expires : Aug19, 2015
Minimum number of days between passwordchange : 0
Maximum number of days between passwordchange : 99999
Number of days of warning before passwordexpires : 7
[root@oldboy ~]# id oldboy7
uid=855(oldboy7) gid=1002(huang) groups=1002(huang)
[root@oldboy ~]# tail -1 /etc/passwd
oldboy7:x:855:1002::/tmp/huang1:/sbin/nologin