Debian – Creating new users via terminal does not assign correct permissions

accountsdebianuseradd

I am creating a new user for a Linux Debian distribution.

I did use the command to create a new user via terminal, while I was logged in as root; tehn assigned the user to the sudo group, so I can install and run commands as superuser when needed (without swap with su).

Is there a sequence of commands to perform, to create a user, create the home folder, assign it to sudo group and such?

This is the sequence of commands that I performed:

<login as root>
useradd myuser
passwd myuser
adduser myuser sudo
usermod myuser -s /bin/bash
<logout and login as myuser>

At this point, I had no home folder set up; created one via sudo but obviously it has Root as owner, so I can't do anything inside it.

I had to use chown to change the home permission, although this doesn't seems right.

What else do I need to do, to have a proper user created?

Best Answer

As muru says, you should just use adduser:

adduser myuser

will prompt for myuser's GECOS information and password, and create myuser's home directory with the appropriate permissions. The default shell should be /bin/bash. adduser will also populate the new home directory with the contents of /etc/skel (default shell initialisation scripts etc.).

All that's needed then is to add myuser to the sudo group, as you're doing already, so the whole sequence becomes

adduser myuser
adduser myuser sudo