Useradd creates home directory but no files or directories inside /home/$user

Hello!

When I try creating a new user profile using the ‘useradd’ command, it shows the new user in etc/passwd and also in /home/$user but said /$user directory is completely empty and trying to log in to that useraccount just shows a blackscreen for a couple seconds before throwing the user back to the login screen

Also I read some stuff about this already and the /etc/skel directory appears to be empty.

How can I give the user a functional desktop and everything?

Hello @FloAtWork and welcome!
When you say “…and the /etc/skel directory appears to be empty.” : Did you list that directory with the -a flag? The reason is that an /etc/skel directory can have hidden files and directories. For instance, on my Rocky Linux 9.1 desktop, the /etc/skel looks like this:

ls -al /etc/skel/
total 24
drwxr-xr-x.   3 root root   78 Jan 27 07:48 .
drwxr-xr-x. 143 root root 8192 Jan 31 08:44 ..
-rw-r--r--    1 root root   18 Jan 23 16:42 .bash_logout
-rw-r--r--    1 root root  141 Jan 23 16:42 .bash_profile
-rw-r--r--    1 root root  492 Jan 23 16:42 .bashrc
drwxr-xr-x.   4 root root   39 Dec  2 09:41 .mozilla

That .mozilla directory is the skeleton file for Firefox (which you may or may not have installed) and the rest will be for the login/logout environment setup, etc. Note that all of these files are owned by the root user and group, so if these files do not exist, you’ll need to be able to sudo to create/fix them. The bigger question is:

  • If they don’t exist, why don’t they exist?

The largest of these files is the .bashrc which should look like this (mostly):

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs
sspencer@sspencer-home:~$ more bashrc.txt 
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
if [ -d ~/.bashrc.d ]; then
	for rc in ~/.bashrc.d/*; do
		if [ -f "$rc" ]; then
			. "$rc"
		fi
	done
fi

unset rc

.bash_profile looks like this:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

And .bash_logout looks like this:

# ~/.bash_logout

So do these hidden files exist in the /etc/skel directory? When you do an ls -al /etc/skel what do you see?

1 Like

How did you create the user password?

1 Like

Can you provide the exact useradd command? /home/$user and /$user from your text above is a different path altogether. Also would be best to copy and paste everything from the command line or screenshot, so we can actually see the error messages.

Also, check /etc/passwd and ensure the home directory here also shows as being /home/$user and not /$user. Perhaps the home directory was created in /home/user, but the passwd entry refers to /user that doesn’t exist? Little difficult to say without actually seeing the full commands, and what the actual error messages exactly are.

1 Like

First of all thanks for the replies!

I looked a bit more into it and it seems I didn’t use the correct flags before. In my etc/skel/ there are the 4 files ‘.bashrc’, ‘.bash_logout’, ‘.bash_profile’ and ‘.mozilla’

Logout and profile seem to be identical to what spencer wrote, bashrc looks a bit different with

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

The exact commands I used were

>useradd $user
>passwd $user

And it also shows said user in etc/passwd with

$user:x:1351:1351::/home/$user:/bin/bash

Funnily I just tried it again with a new test user and this time it worked, however the account I created previously still seems to have the same issues as before. I tried deleting the user and creating it again with ‘userdel $user’ however this leads to the message

[root@$pc etc]# useradd $user
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
Creating mailbox file: File exists

And after setting a password, this user account still can’t log in and is just met with a black screen. After using userdel the /home/$user folder still exists with ‘.bash_history’, ‘.bash_logout’, ‘.bash_profile’ and ‘.bashrc’ in it and trying ‘rmdir /$user’ doesn’t work unfortunately because it’s not empty.

However, I was able to just create another, now working, account for said $user

You can use rm -rf $user to delete if it’s not empty.

1 Like

If you want to delete a user, including his/her home directory, use userdel -r $user. Otherwise, the home directory of $user will still remain.

1 Like