Created a new user and made him the working directory with the following commands:

sudo useradd username sudo mkdir /home/username sudo passwd username sudo chown username /home/username sudo chgrp username /home/username sudo adduser username sudo 

But when I go under this user, I don’t find myself in his home directory and the terminal looks a bit strange (without specifying a user and computer name):

enter image description here

What am I doing wrong ?

  • And why was it necessary to create a folder and change permissions? - don Rumata
  • When creating a user, you can use the -m key, and the home directory will be created automatically. useradd -m user. - V. Makhnutin

2 answers 2

From man useradd: useradd is a low-level command for adding users, in Debian you should usually use adduser instead.

In addition to the actions you have done, adduser itself creates the user's home directory and copies the configuration files from / etc / skel, assigns the shell to the user from /etc/adduser.conf and can perform other initialization actions if they are defined in /usr/local/sbin/adduser.local .

However, after the actions you specified, you should have been in the home directory /home/username to verify this type pwd .

    useradd does not create the user's home directory if you have not used the -m option. With it, the directory is created automatically. Probably due to the fact that for some reason you decided to create a home directory manually, an entry about your home directory was not added to the /etc/passwd for your new user. You can verify this by running the grep username /etc/passwd .

    To add the name of the home directory for a user to the /etc/passwd , run the command usermod -d /home/username username .

    After that, copy the contents of /etc/skel into your home directory.