命令介紹
命令:useradd 添加用戶
用法:useradd -D [options] useradd 用戶
命令選項
[root@fp-21 ~]# useradd --help
-c, --comment COMMENT # 添加備註信息
-d, --home-dir HOME_DIR # 指定用戶的家目錄
-D, --defaults # 打印或更改用戶的配置
-e, --expiredate EXPIRE_DATE # 用戶的有效期限
-f, --inactive INACTIVE # 過期緩存天數(過期還能使用多少天)
-g, --gid GROUP # 指定用戶所屬的羣組
-G, --groups GROUPS # 指定用戶所屬的附加羣組
-h, --help # 幫助文檔
-l, --no-log-init # 不將用戶添加到lastlog和faillog數據庫
-m, --create-home # 自動創建家目錄
-M, --no-create-home # 不自動創建家目錄
-N, --no-user-group # 不創建用戶組
-p, --password PASSWORD # 新用戶的密碼
-r, --system # 建立系統賬號
-s, --shell SHELL # 指定用戶登陸後使用的shell
-u, --uid UID # 指定用戶的UID
-U, --user-group # 創建與用戶同名的組
命令實例
# 添加備註信息
[root@fp-21 ~]# useradd -c "This is first user" test01
[root@fp-21 ~]# tail -1 /etc/passwd
test01:x:1001:1001:This is first user:/home/test01:/bin/bash
# 指定用戶的家目錄
[root@fp-21 ~]# useradd -d /opt/test test02
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
# 指定用戶所屬的羣組
[root@fp-21 ~]# useradd -g test01 test04
[root@fp-21 ~]# tail -1 /etc/passwd
test04:x:1004:1001::/home/test04:/bin/bash
# 不創建用戶組
[root@fp-21 ~]# useradd -N test07
[root@fp-21 ~]# tail -2 /etc/passwd
test07:x:1007:100::/home/test07:/bin/bash
# 指定用戶的UID
[root@fp-21 ~]# useradd -u 666 test10
[root@fp-21 ~]# cat /etc/passwd |grep 666
test10:x:666:1010::/home/test10:/bin/bash