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

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

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

我尝试过使用 /etc/default/useradd 配置文件,但没有成功。

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

答案1

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的:

   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).

相关内容