Directory

創建新使用者時如何自動創建一個空目錄?

  • April 1, 2017

我正在嘗試這樣做,因此當我使用 useradd 或 adduser 創建新使用者時,會在該使用者的主目錄下自動創建一個名為“whatever”的空目錄。

我試過玩弄 /etc/default/useradd 配置文件,但沒有運氣。

我不是要更改每個新使用者的預設主目錄,而是在創建新使用者的同時自動創建一個空目錄。

sudo mkdir -p /etc/skel/whatever

/etc/skel是新使用者主目錄的“骨架”;位於其中的任何東西都被複製為新使用者家的起點。

例如,從手冊頁useradd

  -k, --skel SKEL_DIR
      The skeleton directory, which contains files and directories to be
      copied in the user's home directory, when the home directory is
      created by useradd.

      This option is only valid if the -m (or --create-home) option is
      specified.

      If this option is not set, the skeleton directory is defined by the
      SKEL variable in /etc/default/useradd or, by default, /etc/skel.

      If possible, the ACLs and extended attributes are copied.

或從adduser’s:

  adduser will copy files from SKEL into the home  directory  and  prompt
  for  finger  (gecos) information and a password.  The gecos may also be
  set with the --gecos option.  With  the  --disabled-login  option,  the
  account  will  be created but will be disabled until a password is set.
  The --disabled-password option will not set a password,  but  login  is
  still possible (for example with SSH RSA keys).  To set up an encrypted
  home directory for the new user, add the  --encrypt-home  option.   For
  more information, refer to the -b option of ecryptfs-setup-private(1).

引用自:https://unix.stackexchange.com/questions/355174