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.

Advertisements

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

xyz:x:501:501:ZYX:/home/xyz:/bin/bash

which is

username:passsword:userid:userprivategp:comment:userhomedirectory:bashfile

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

or

chmod 777 filename

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

chown user.group <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

then

sudo su

authenticate using the password added