1

I have a file (a document or text file to be precise) that I would like to be copied for every new user I create in the future. Is this possible? For example If I were to create a new user "test", my file should automatically be copied to the user "test" without me doing anything.

Also is it possible to change the default location of the file to be copied? I don't want it to be copied to the home directory?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • 3
    Doesn't /etc/skel get copied? Is it possible to add the file there? – KevinO Jun 01 '17 at 16:46
  • Hello thank you for the quick reply, I am very new to Linux so I don't know. But thanks for the info. Will check! – Nagarjun Prasad Jun 01 '17 at 16:47
  • @KevinO yes it does. That's what it's for. Please post that as an answer. – terdon Jun 01 '17 at 16:49
  • @KevinO Is it possible to change it's default location from home directory to something else? – Nagarjun Prasad Jun 01 '17 at 16:52
  • @NagarjunPrasad, what do you mean by "something else"? `/etc/skel` can (and does) contain subdirectories. – KevinO Jun 01 '17 at 16:55
  • @KevinO What I meant to say was that instead of the file being copied to the home directory can I make it so that it's copied to some other location, say /bin directory, it doesn't specifically have to be /bin? – Nagarjun Prasad Jun 01 '17 at 17:07
  • If you put a file into `/bin`, it will be there for all users. If you mean to populate a new user's own binaries in e. g. `~newuser/bin`, just create a directory `/etc/skel/bin` and put a (presumably executable) file within it. – DopeGhoti Jun 01 '17 at 17:09

2 Answers2

4

When a user is added to the system, by default the settings in /etc/skel are copied to the home directory of the user.

It is therefore possible to add files to /etc/skel and have those files copied.

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

KevinO
  • 845
  • 2
  • 7
  • 17
0

When a new user's home directory is created, it will be a copy of /etc/skel (short for "skeleton" I presume).

If you put your file there, all new users will get a copy of it. You may create a subdirectory for it if you wish.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936