Why useradd -m doesn't fill created home dir with some defaults?
Solution 1
When a new home directory is created by adduser
or useradd
, the home directory is populated with the contents of /etc/skel
(the "skeletal home directory", see man adduser
and/or man useradd
). This directory contains the initial dot-files, like .bashrc
etc., that all users get. The Desktop
etc. directories are usually not part of the contents of she skeletal home directory since a user may not even want to run a desktop environment (or one that uses those directories).
These directories are created when the user logs in and starts a graphical desktop environment.
Would you want these extra directories (or any other file or directory) to be part of the skeletal home directory, then create them in /etc/skel
, assuming the user's graphical desktop environment does not have issues with these directories already existing (I don't use Linux-like desktops, so I don't know).
Solution 2
For me , by default, the /etc/skel contains just 3 hidden files, .bash_logout
, .bashrc
and .profile
, which can be displayed with ls -a
.
Your command should work, have you checked the content of your /etc/skel directory ?
Related videos on Youtube
Alex Silkovsky
Updated on September 18, 2022Comments
-
Alex Silkovsky over 1 year
My motives:
I want to create deployment script which prepare all system with just 1 click, and although learn Linux this way. So I don't want to use interactive utils like
adduser
(all interaction info I put in some settings.txt).My system:
Debian 8.2 (jessie)
I want:
Create user account with home directory and default folders inside. Like
adduser
do but withuseradd
.My problem:
There is paragraph in
man userradd
:-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.
I looked in /etc/adduser.conf to find the value of SKEL variable for
adduser
. And it is /etc/skel.But after I run some
useradd -m myuser -k /etc/skel
, I've got empty /home/myuser directory.Update 1
After I created some additional file, it alsought copied to the new user home directory (with 3 hidden files). So it means that /etc/skel doesn't impact on such folders as: Desktop, Downloads, etc. But in this case what does?
-
smw over 8 yearsThe directories you are referring to are part of the
xdg-user-dirs
I think, and are specific to "desktop" environments: IIRC they are created by the system when the user first instantiates an appropriate Xsession, based on the templates in /etc/xdg/user-dirs.defaults
-
-
Alex Silkovsky over 8 yearsI although found 3 hidden files inside /etc/skel. (post updated)
-
magor over 8 yearsYou have to create the folders/files in
/etc/skel
. For example, I created/etc/skel/Desktop/test.sh
and for the new user, the folder/home/myuser/Desktop
was created containing thetest.sh
file .