创建新用户时如何自动创建空目录?

Jam*_*ith 4 users directory home useradd

我试图做到这一点,当我使用 useradd 或 adduser 创建新用户时,会在该用户的主目录下自动创建一个名为“whatever”的空目录。

我试过玩弄 /etc/default/useradd 配置文件,但没有运气。

我不是要更改每个新用户的默认主目录,而是在创建新用户的同时自动创建一个空目录。

Dop*_*oti 7

sudo mkdir -p /etc/skel/whatever
Run Code Online (Sandbox Code Playgroud)

/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.
Run Code Online (Sandbox Code Playgroud)

或来自adduser的:

   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).
Run Code Online (Sandbox Code Playgroud)