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

Friday, February 5, 2016

Cut

Cut is a command that allows you to output certain portions of the line. it gives you many ways to do this:

delimiters and field lists:

delimiters and field lists allow you to chunk out lines separated by characters for instance:
head -n 1 etc/passwd/ |cut -d ':' -f 1
outputs:
root

as you can see -d is the delimiter and -f is the field list. here the character they are separated by is ':' and the section they are showing is 1. you can even use -s to bypass lines that dont contain field delimiters

charicters:

characters are the simplest way to use cut. it just outputs the characters in a range. for example:

head -n 1 etc/passwd/ |cut -c 2-4
outputs:
oot

as you can see -c is the character range.

bytes:

bytes allows you to specify the amount of bytes you want the output to take up. I am not going to give an example for this. all you need to know is that -b is bytes. 

Heads/ Tails

Head and tail  are two simple commands.

 the first one head gives the first ten lines of a file for instance:

head /etc/passwd
outputs:
root
bin
deamon
adm
lp
sync
shutdown
halt
mail

the secon
root
bin
deamon
adm
lp
d one: tail gives the last ten words of a file to use a similar example:

tail /etc/passwd
outputs:
avahi
tcpdump
jelkner
student
systemd-bus-proxy
systemd-network
geoclue
setroubleshoot
jjohnson
hrodriguez





now people dont always want just the first or last ten words in a line. sometimes they want the first/last four or first/last twenty seven. to do this we use the:

-N parameter 

the -n parameter tells the computer how many lines you want it to output for instance:

head -n 5 /etc/passwd

gives you:
root
bin
deamon
adm
lp

or
tails -n 15 /ect/passwd

gives you:
pulse
gdm
gnome-initial-setup
postfix
sshd
avahi
tcpdump
jelkner
student
systemd-bus-proxy
systemd-network
geoclue
setroubleshoot
jjohnson
hrodriguez