Sunday, July 19, 2015

System Management

SYSTEM COMMANDS


uname -a
Display linux system information 


uname -r
Display kernel release information


last reboot
Show system reboot history


date
Show current date and time


cal
Show current month calendar4


whoami
Who you are logged in as 


finger user
Display information about user


cat /proc/cpuinfo
Show cpu info


cat /proc/meminfo 
Show memory information

 
man command
Show manual for command


df
Check filesytem storage

 
du
Check subdirectories

 
df -h            
Shows file size which is user readable


du --max-depth=1 -h  
Check subdirectories by one level down

 
whereis app
Show possible location of app


which app
Show which app will be run by default
 

free      
To check ram & swap partition  usuage


free -g
To see usuage in gigabytes


dd if=/dev/zero of=/swapfile bs=1024 count=1024
dd to create a storage file
if=/dev/zero : Read from /dev/zero file.  /dev/zero is a special file in that provides as many null characters to build storage file called /swapfile.
of=/swapfile : Read from /dev/zero write storage file to /swapfile.
bs=1024 : Read and write 1024 BYTES bytes at a time.
count=1024 : Copy only 1024 BLOCKS input blocks.


mkswap /swapfile 
To setup a linux swap area in a file.


swapon /swapfile
Enable the swap file.


swapoff /swapfile
Disable the swap file.
Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 64 MB swap file is 65536. 


lvextend -l +100  /logical/volume00
Extend the logical volume 00 from blank space i.e. 0mb to volume 00 with 100 mb...


ctrl+alt+f1    
GUI (Graphical mode) to text mode i.e. CLI(Command Line Interface)


ctrl+alt+f7    
Text to graphic mode

Types Of Boot Loader
grub  grand unified boot loader
lilo linux bootloader

 
kcontrol &      
Configure the kde enviroment


gnome-control-center      
Configure the gnome enviroment

 
switchdesk kde  
Set the default startup to kde


switchdesk gnome  
Set the default startup to gnome


up2date-config      
Configure the red hat for update

mount /dev/sda1  /tmpdir         mount the sda1 file in tmpdir directory
mount /dev/sda0 /tmpdir          mount the sda0 file in tmpdir directory
unmount  /tmpdir/boot              unmount boot directory
unmount /tmpdir                       unmunt tmpdir directory
 

sync
Sync the changed or changes take effect

 
top    
Will show the running process list
 

gnome-system-monitor  
Show the graphical mode of running process

 
uptime    
Show how long the system is running from last boot  and
load average of first no show the the total load in last one minute 
load average of second no show the the total load in last five minute
load average of third no show the the total load in last fifteen minute

Maintenance of linux system

BACKUP


Commands for Backup

tar
Options:
c         --  create
v         -- verbose means it will show all the error while creating creating backup.
p         -- same permission i.e. maintains the same permissions of file which is backed-up
f          -- specifies filename
t          -- table of content
x          -- extract to
z          -- zip/gzip
w        -- ask for confirmation

To create a backup

Type1: tar --create --verbose --same-permission --file /usr/backup1 /home /etc
Type2: tar -cvpf /usr/backup1 /home /etc

c-create
v-verbose  
p-maintains the same permissions of file which is created
f-to create a file
/usr  is the directory were backup is saved
backup1 is the name of backup file created
/home & /etc are the directory for which backup is created
 

To extract the content from backup
tar -xvpf /usr/backup1


To extract a specific file from backup
tar -xvpf /usr/backup1 /home/haktuts.txt
to extract haktuts.txt file from backup1 to the directory /home/haktuts.txt


To list the content of backup
tar -tvf /usr/backup1 | more
list view of files in backup useful for recovering file which name is not known


To create a zip file
zip
e.g. zip hak /usr
hak is the filename
/usr is the directory to save the zip file


To extract the zip file
unzip hak /etc


To create a gzip file
gzip filename
e.g: gzip hak


To extract a gzip file 
gzip -d filename
e.g.: gzip -d hak.gz

User & Group Adminstration

User

1 : Show the details of all users
 user -D                          


2 : To add new user in system
useradd name

3 : To delete particuler user from the group
userdel -r name


4 : usermod command is used for modifying user
eg:

If user want to insert comment then
 usermod -c "comment"  user name

5: To set the password on particuler user command will be
passwd username


Group Administration

1 : To add new group named projectX command will be
groupadd projectX 

2 : To remove group named projectX command wil be
groupdel projectX

3 : To add user in a group
usermod -G

eg: To add username haktuts in a group name called projectX
usermod -G project X haktuts

4 : To add user in a multiple group
usermod -G

eg: To add username haktuts in a group name called projectX and project Y
         
usermod -G projectX,projectY haktuts

5 : How to provide admin right to specified user in a particuler group
gpasswd -A username groupname 

6 : To add user in a group
 gpasswd -a username groupname

7 : To remove group named projectX command wil be
 gpasswd -d username groupname 

8 :create new group called abcd          
newgrp abcd  
Note: User can be add in a group via usermod as well as gpasswd  command                                              

 
User and Group Databases file 


1 : To check the all set password  go to directory
cat /etc/passwd

2 : To see password which is set in encrypted form
cat /etc/shadow 

3 : To check detail of all the group
cat /etc/group



How to Read the passwd file located in etc directory?


username:x:1000:1001::/home/username
username i.e name of user
x   stands for password of user which is masked
1000 is the user id
1001 is the group id
::   user  comment between collens
/home/username  Home directory of user



How to Read the shadow file located in etc directory?



username:xyzxyzxyz:11111:0:9999:7:::
username i.e name of user
xyzxyzxyz   stands for password of user which is masked or encrypted form
11111  stands for  No.of days since 1970
0  stands for minimum no of days to change the password
9999  stands for max no of days to change the password
7  stands for warning period
Note Password is encrypted through data encryption standard or MD5 algorithm

 
Types of user 


There are two types of user
1 System users
2 Normal users
id from 0-499 is reserved for system user and 500-60000 is for normal user.

VIM

Vim is simply an improved version of Vi. It pretty much has a ton of stuff that Vi doesn’t.

Within Vim you can see the differences between Vi and Vim by running the following command  :h vi-differences.

root@MR-X:~$ Vi
[It will create a Blank file.]

root@MR-X:~$ Vi
[It will create multiple file at once.]

root@MR-X:~$ Vi file1.txt
[to open file1.txt using Vi]
[press i  - to insert text in file1.txt]
[press Shift+: and then type wq  to save and quit.
            : q  to exit without any changes in file
            : x  to save changes and exit.]




VIM

Quitting


:x - exit, saving changes
:wq - exit, saving changes
:q - exit, if no changes
:q! - exit, ignore changes 

Inserting text 


i - insert before cursor
I - insert before line
a - append after cursor
A - append after line
o - open new line after cur line
0 - open new line before cur line
r - replace one character
R - replace many characters 

Motion


h - move left
j - move down
k - move up
l- move right
w - move to next word
W - move to next blank delimited word
b - move to beginning of the word
B - move to beginning of blank delimited word
e - move to end of word
E - move to end of blank delimited word
( - move a sentence back
) - move a sentence forward
{ - move paragraph back
} - move paragraph forward
0 - move to beginning of line
$ - move to end of line
nG - move to nth line of file
:n - move to nth line of file
G - move to last line of file
fc - move forward to 'c'
Fc - move backward to 'c'
H - move to top of screen
M - move to middle of screen
L - move to bottom of screen
% - move to associated (),{},0 

Deleting text


x - delete character to the right
X - delete character to the left
D - delte to the end of line
dd - delete current line
:d - delete current line 

Searching


/string - search forward for string
?string - search back for string
n - search for next instance of string
N - for for previous instance of string 

Replace 


:s/pattern/string/flags - replace pattern with string, according to flags
g - flag, replace all occurences
c - flag, confirm replaces
& - repeat last :s command

Files 


:w file - write to file
:r file - read file in after line
:n - go to next file
:p - go to previous file
:e file - edit file
!!cmd - replace line with output of cmd 

Other 


u - undo last change
U - undo all changes to line

File Management in Linux

File Permission


- rwx rwx rwx


- means file
r means read
w means write
x means excute
first rwx is for user permission
next rwx is for group permission
and last rwx is for other permission

- means permission is for file
d means permission is for directory
l means for links
p means for process file
s means for socket file
b means for block device
c means for character device
Note:if permission started with d instead of - .It means particuler permission is for directory.


 




How to change the file or directory permission

 

chmod command is used to change the permission
File or Directory permission can be change in two ways
Method 1
chmod
eg:
1 : if user file permission change from rwx to rw only
chmod u+rw filename
2 : if user and group file permission change from rwx to rw only
chmod ug+rw filename

Method 2
chmod
eg:
1 : if user file permission change from rwx to  rw only  ,group file permission change from rwx to r only and other file permission change from rwx to r only
chmod 644 filename


 

Changing file ownership

You can change the owner of a file by using the chown command
chown  
eg:
1 :  I wanted to change the owner of file from "Haktuts" to "hak".
chown hak filename

Changing group ownership
You can change the owner of group by using the chgrp command
chgrp  
eg:
1 :  I wanted to change the owner of group from "Haktuts" to "hak".
chgrp hak filename

changing user and group ownership
chown : filename
eg:
if user want to change both user and group ownership
chown haktuts:hak filename
 

Basic Commands

Basic Commands



root@haktuts:~$ pwd
[pwd will show the Present working directory]
 

root@haktuts:~$ ls
[ls will show the list of file and directory of present working directory.]


root@haktuts:~$ ls b*
[ls b* will show the list of file and directory starting with b and end with anything.]


root@haktuts:~$ ls -l  

[Listing of all files and directory along with attributes(i.e. more detailed format like file permission,file size etc.]


root@haktuts:~$ ls -a
[Listing of all files and directory along with hidden file or file starting with periods (i.e. file stating with *  like *bashrc]


root@haktuts:~$ ls -R
[show the listing of file and directory in tree structure.]


root@haktuts:~$ cat Haktuts.txt
[user can use the command cat to see the preview of Haktuts.txt file.]


root@haktuts:~$ cat > Hak.txt
[use to create file]


root@haktuts:~$ cat Haktuts.txt Hak.txt >>new.txt
[transfer the content of Haktuts.txt and Hak.txt to new.txt file.]


root@haktuts:~$ cd
[To change the directory.]


root@haktuts:~$ cd com
[go to directory name com .]


root@haktuts:~$ cd ..
[change the directory one level back.]


root@haktuts:~$ cd ../..
[change the directory two level back.]


root@haktuts:~$ cd ~
[change the directory to home directory.]
 

root@haktuts:~$ Vi
[It will create a Blank file.]
 

root@haktuts:~$ Vi
[It will create multiple file at once.]
 

root@haktuts:~$ Vi file1.txt
[to open file1.txt using Vi]
[i- to insert text in file1.txt]
[press Shift+: and then type wq  to save and quit.
            : q  to exit without any changes in file
            : x  to save changes and exit.]
 

root@haktuts:~$ mkdir com
[It will create a directory name com]
 

root@haktuts:~$ mkdir com lap mob
[To create multiple directories]


root@haktuts:~$ mkdir -p com/lap/mob
[To create a  directory with their subdirectory]


root@haktuts:~$ cd -
[go to last working directory.]
[eg:currently user in /home/Haktuts/Desktop directory and user last working directory is /root/Desktop . so as and when user type cd - user directly go to /root/Desktop directory.]


root@haktuts:~$ rm Haktuts.txt
[rm remove the file Haktuts.txt.]


root@haktuts:~$ rmdir com
[rmdir remove the directory name called com only if the com directory is empty.]


root@haktuts:~$ rm -rf com
[rm -rf  remove the directory and also the content or data available in directory.]


root@haktuts:~$ cp Hak.txt /root/Desktop
[copy the file Hak.txt to /root/Desktop Directory.]


root@haktuts:~$ cp -r com /root/Desktop
[copy the directory com to /root/Desktop directory.]


root@haktuts:~$ mv Haktuts.txt /home
[move the file Haktuts.txt to /home directory]


root@haktuts:~$ mv Hak.txt Hak2.txt
[rename the file Hak.txt to Hak2.txt]

Intro to linux file directory




/             This directory is called superuser home directory.It is the top of file system structure.All other directory are mounted under it.
/boot      This directory contain the kernal image file.This also contain the files related to booting the system such as bootloader.
/etc         It contain the whole system configuration file.
/home    This is the all users home directory.
/mnt       This is a generic mount point under which you mount your filesystems such as cdrom,floppy.
/proc      It is not a real file system, it is a virtual file system.This directory is empty until the proc  file system is mounted.
/sys        Modern Linux distributions include a /sys directory as a virtual filesystem (sysfs, comparable to /proc, which is a procfs), which stores                    and allows modification of the devices connected to the system.
/dev       This directory contain the devices nodes through which the operating system can access hardware and software devices on the system.
/bin        This directory contain the command used by superuser and normal user.
/sbin      This directory contain the command used by superuser only.
/lib         It contain the library required for running the additional application and running the linux kernal.It also contain the library essential for                   binaries in /bin and /sbin.

Evil Twin attack

Evil Twin Attack is attack is frequently carried upon wireless access points with malicious intentions. This attack happens when...