useradd 的 -d 和 -m 选项有什么区别?

sha*_*333 4 useradd

当我们使用useradd,之间有什么区别-d-m?因为两者的定义听起来很相似,它负责创建一个主目录。

Dan*_*Dan 9

这两个选项并不是很相似,但它们可以一起工作。如果您查看联机帮助页,useradd您会发现以下内容:

       -d, --home-dir HOME_DIR
           The new user will be created using HOME_DIR as the value for the user's login
           directory. The default is to append the LOGIN name to BASE_DIR and use that as the
           login directory name. The directory HOME_DIR does not have to exist but will not be
           created if it is missing.

       -m, --create-home
           Create the user's home directory if it does not exist. The files and directories
           contained in the skeleton directory (which can be defined with the -k option) will be
           copied to the home directory.

           By default, if this option is not specified and CREATE_HOME is not enabled, no home
           directories are created.
Run Code Online (Sandbox Code Playgroud)

-d选项只是设置创建的用户的主目录所在的位置,但如果它不存在则不会创建它。如果该-m选项-d不存在,则该选项将创建由其设置的主目录。

  • 并非每个 Linux 都有 `adduser`,例如 Arch Linux 及其衍生产品。 (2认同)