Adding Users and Creating Home Directory in Ubuntu

So it turns out that if you just issue useradd command in your linux machine you will create a user but there will be no home directory. Th problem the added user will not be able to login in his home directory. He can login using cli but not otherwise. So here is how to create user home directory when adding a user

sudo useradd -d /home/testuser -m testuser

sudo passwd testuser


this is a as simple as that and another way is using the adduser command in which you can add more detail for the user like phone number and all.

User Administration in Ubuntu

To add a user use the following command

>useradd xyz

when you run the following command a bunch of config files from the /etc/skel directory on your system gets copied in the users home directory.

To set a user password we have to run the following command

passwd  <username>

The password gets stored in the /etc/shadow file and it is encrypted. In the /etc/passwd file our new user gets added in the following format


which is


adding a group

groupadd -r projectX

the -r in groupadd gives the group an id of below 500 in red hat linux as id greater than 500 is reserved for user private group

adding a user to a group

usermod -G projectX,projectY[,groups1,2,3] <username>

you will have to remember all the groups that user is already in if you dont include it the user gets removed from that group

File permissions for users

-(rwx)(rwx)(rwx) for files

user,group,other permissions

d(rwx)(rwx)rwx) for directories the starting ‘d’ indicates a directory

giving permissions to users

chmod g+w filename


chmod 777 filename

to give ownership of a directory or a file to the user

chown <filename>

making a user admin of a directory

gpasswd -A <user> <group>

gpasswd -A bob projectX

now bob can add anyone he likes to the group without permissions from the admin

gpasswd -a alice

gpasswd -d alice to delete alice

activating the superuser in ubuntu 12.04

sudo passwd root

add  a password


sudo su

authenticate using the password added