2

I need to automatically assign every new user that gets created a certain folder Sales in their home directory. (e.g. when you add the user tim, tim automatically gets a folder named Sales in his home directory)

How can I do this?

2
  • Unsure if this is what you are looking for but the adduser command has hooks to customize e.g. the directory layout for newly created accounts.
    – tripleee
    Nov 30, 2015 at 20:29
  • 1
    Hi user_01 did you notice the answers? Could you let us know if it is helpful (or not), or if anything is clear? Dec 1, 2015 at 9:41

2 Answers 2

6

All new users' home directories are copies of /etc/skel when the user gets created through any method that automatically creates a home directory.

If you are sure that you need the Sales folder on every new user account's home directory, you can just create the folder in /etc/skel.


Make sure the owner and permission of everything you create or modify in there is correct.

Set the permissions you want, they will be copied to the new user's home directory as they are. Usually you take 644 (octal representation) or rw-r--r-- (string representation). You can modify this with one the commands below. Make sure everything is owner-readable and all directories are owner-executable (otherwise the owner can't list or access their content).

  • sudo chmod 644 /etc/skel/FILE_OR_DIRECTORY to set permissions for a single file or directory using the octal representation.
  • sudo chmod u=rw,g=r,o=r /etc/skel/FILE_OR_DIRECTORY to set permissions for a single file or directory using a syntax similar to the string representation.
  • sudo chmod -R 644 /etc/skel to recursively set permissions for all files and directories using the octal representation.
  • sudo chmod -R u=rw,g=r,o=r /etc/skel to recursively set permissions for all files and directoriesusing a syntax similar to the string representation.

The owner should be root. You change this recursively on all files and folders in /etc/skel with the command below:

sudo chown -R root: /etc/skel
0

A relatively simple alternative would be to create a starter in /etc/xdg/autostart, that will create a folder in (any) user's home directory on log in, only if the folder does not exist yet.

  • Create a file with the following lines:

    [Desktop Entry]
    Name=Create Sales
    Exec=/bin/bash -c "mkdir ~/Sales"
    Type=Application
    
  • Save it as sales.desktop (the extension is essential)

  • Run the command:

    sudo cp /path/to/sales.desktop /etc/xdg/autostart
    

This will create a folder ~/Sales in the home directory of any user once he or she logs in (only if it doesn't exist).

Explanation

To run a command on startup (log in actually) locally, for one user only, we can put a .desktop file in ~/.config/autostart

If we do the same, but store the .desktop file in /etc/xdg/autostart, the command runs locally as well, but similarly for any user on log in.

If we make the .desktop file run the command:

/bin/bash -c "mkdir ~/Sales"

we make sure the folder is created, even re- created on the next log in if the user might remove it manually. At the same time, if the folder exists, the command will not be executed, so existing folders will not be overwritten.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .