Thursday, February 18, 2016

useradd/passwd/usermod

User add/passwd/usermod


This is one of the most important commands to learn

what does it do?:
it allows you to create users

so say for example you wanted to make an account for bruce wayne:

sudo useradd bruce_wayne  -m

 the -m here tells the computer to create a home directory if it does not exist
you can also use:  -M to tell the computer not to create a home directory for the user

but that is not too secure because there is no password to do this we use passwd

sudo passwd bruce_wayne 

for this demonstration we are using 'batman' as the password

 what if you dont want the password to stay the same for too long? then you use -e: 

-e tells the computer when this user account password will expire

this date is the amount of seconds from the epoch or 1/1/1970 this is because that was the year UNIX was officially invented.

we are going to use October 5th 2277 in UNIX that is: 9693475200

sudo useradd bruce_wayne  -m -e 9693475200

Unfortunately -e presents us with a problem what do you do a user account is inaccessible for too long? You use -f. -f tells the computer how long this account's password can be expired before it deletes the account. this is presented as days before the user account will terminate itself. for this we are going to give this a week

sudo useradd bruce_wayne  -m -e 9693475200 -f 7


groups:

groups are a big part of user management. so it makes sense that there are group tools inside of useradd.

first how do we designate the group a user is in? we use -g. -g sets the name or number of the group that the user will be created in. 


sudo useradd bruce_wayne  -m -e 9693475200 -f 7 -g 'justice league'

if you want the user to be part of more groups you use -G. -G sets the names of the other groups this user is a part of.


sudo useradd bruce_wayne  -m -e 9693475200 -f 7 -g 'justice league' -G 'detective comics'

you can even have it create a group with the same name as the user with -n


sudo useradd bruce_wayne  -m -e 9693475200 -f 7 -g 'justice league' -G 'detective comics' -n

these are some other useful options: 
---------------------------------------------------------------------------------------------------------------------------------
-b this tells the computer what the base directory will be or in plainer English what directory you start in on this account.

-c allows you to connect any text string as a description for the user

-h help  tells the computer to display the help message and exit

-l this tells the computer to not have the user added to the last login file.

-r this is used to flag the account as a user account

-s tells the computer a login shell that the account will use

-u allows you to choose the user id for the account

-------------------------------------------------------------------------------------------------------------------------------------
 User mod:

so after you make your account how are you going to edit the user? Well you use Usermod!

here are some options on usermod


-a, allows you to add the user to the following group
-c, this is used to change the comment in the passwd folder

-d, this changes the users home directory to the following group

-e, his changes the user's password experation date

-f, this changes the number of days that the user account can be expired before deletion

-g, his changes the users initial group

-G, this allows you to add the user to the following groups

-l,  this changes the name of the user

-L, his locks the user's password

-m, his allows you to move the users home directory

-o, When used with the -u option, allows to change the user ID to a non-unique value 
 
-s, this changes the users login shell

-u, this changes the users UID

-U, this unlocks a user password

No comments:

Post a Comment