通过命令行创建具有不同配置文件的 Linux 用户

Create a Linux user with different profiles by command line

我想知道在 Linux 中添加用户时是否可以覆盖 SKEL 属性。

手册页为我提供了动态更改任何 属性(SHELL、HOME、...)但不是 SKEL 的所有内容。

我想做的是找到一种方法将一个或另一个配置文件分配给我正在创建的用户。

例如,我需要创建一个 .profile 的用户,其中 VAR=value1,以及另一个 .profile 的用户,其中 VAR=value2。我的想法是创建不同的 SKEL,一个给那些需要 VAR=value1 的人,另一个给那些需要 VAR=value2 的人,然后简单地执行 adduser ... -D -magic_option /SKEL/for/value1adduser ... -D -magic_option /SKEL/for/value2。但是-magic_option好像不存在

有什么建议吗?

当然,只要使用useradd中的-k选项即可:

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

所以你可以创建你的 /my/skel_for_users/my/other_skel_for_users 并在创建一个时使用它们中的任何一个。