1. 添加新用戶時,修改用戶的默認家目錄/home,將/etc/default/useradd文件中的HOME替換為目標目錄即可(紅色字體所示)
$ cat /etc/default/useradd
# Default values for useradd(8)
#
# The SHELL variable specifies the default login shell on your
# system.
# Similar to DHSELL in adduser. However, we use "sh" here because
# useradd is a low level utility and should be as general
# as possible
SHELL=/bin/sh
#
# The default group for users
# 100=users on Debian systems
# Same as USERS_GID in adduser
# This argument is used when the -n flag is specified.
# The default behavior (when -n and -g are not specified) is to create a
# primary user group with the same name as the user being added to the
# system.
# GROUP=100
#
# The default home directory. Same as DHOME for adduser
# HOME=/home #更改為自己想指定的家目錄,比如:/app/users
2. 如果不更改useradd文件,可以通過選項-b來指定,
$useradd -b /app/users -rms /bin/bash zhangsan
相關選項參數:
-c:加上備注文字,備注文字保存在passwd的備注欄中。
-d:指定用戶登入時的啟始目錄。
-D:變更預設值。
-e:指定賬號的有效期限,缺省表示永久有效。
-f:指定在密碼過期后多少天即關閉該賬號。
-g:指定用戶所屬的群組。
-G:指定用戶所屬的附加群組。
-m:自動建立用戶的登入目錄。
-M:不要自動建立用戶的登入目錄。
-n:取消建立以用戶名稱為名的群組。
-r:建立系統賬號。
-s:指定用戶登入后所使用的shell。
-u:指定用戶ID號。 #設定ID值時盡量要大於500,以免沖突。因為Linux安裝后會建立一些特殊用戶,一般0到499之間的值留給bin、mail這樣的系統賬號
結束。
