01.0.1 Environment Variables, Aliases And Shell Configuration Files
customize comand prompt
global configuration file is inside /etc
/etc/ bash.bashrc
apply to anyuser
export EDITOR=”vi”
export EDITOR=”nano”
echo $EDITOR
echo $PS1
export PS1=”\[\u@awesome]$”
global configuration file inside etc/
vi bash.basrc
01.02. Modifying Bash Shell Configuration Files
or profile.d/
bash folder/
ls | grep bash
/var/log
alias syslog=”tail -f /var/log/syslog”
add lin in bash.basrc
export HELLO =”this is tyou hellol variable”
cd /etc/skel
/etc/profile.d
01.03. Learn How To Change The Bash Prompt
variable are key sensitive
export PS1=”SMAIL”
/var/mail/user
export PS1=”hello \u@\h”
01.03. Learn How To Change The Bash Prompt
export PS1=”hello \u@\h your cuurent directory is \w”
is time \T or \t \D date
you have currently have \j running
\j jobs
color
\e[ here put the color code <— Idicate of begingi of color prompt
export PS1=”\e[0; u@\h \$””
export PS1=”\e[1;30m\]; u@\h \$”
1 represent dark
export PS1=”\e[1;30m\]; u@\h \$”
export PS1=”\e[34\e[m u@\h \$”
01.04. Bash Lists
man bash
&
&&
||
cat command
#!/bin/bash
echo”First command”
exit 1
cant command2
#!/bin/bash
echo ” second command”
exit 0
ls && cd /etc
./command2 && ./command
./command || ./command2
|| only the first command failes
; move on to next command
cd; ls; cd /etc; ls
cd &
02.01. In
stalling MySQL on Ubuntu And CentOS
/ Connect to mysql
set new password mysql
mysql -uroot -p
password:
show database
mysql > select
use mydb
create table mydb.customers (‘id’ init(11)) NOT NULL, ‘first_name’ varchar(20) NOT NULL, ‘last_name’ varchar(20) NOT NULL)
show table;
INSERT INTO customers (id,first_name,last_name) VALUE (1,”jeff”,”jefferson”);
CREATE USER ‘jeff’@’localhost’ IDENTIFY BY ‘test’;
SELECT user,host FROM mysql.user;
GRANT ALL PRIVILAGES ON mydb.customers TO ‘jeff’@’localhost’;
drop database mydb;
import data dump sql
mysqldump -uroot -p storedbname > backup_store.sql
mysql -uroot -p storedbname < backup_store.sql
useradd -M testuser ( without home directory)
/skel/ directory with template for users
/etc/skel/ <— everthing inside will show on the new user home
/etc/passwd
/etc/shadow file for with encrypted password
mysqldump -uroot -p databasename > backupfiledb.sql
mysql -uroot -p databasename < filewithbackup.sq;
03.01. Adding Linux Users Using useradd, Customization And Flags
useradd nameofuser
userdel -r nameofuser
-d
-e
useradd -M anthony
-g primary group
-f password expired
-f 0 luck after password expired
-k skel directory
useradd test_user -k /home/test_skel/
03.02. Useradd Examples
remove user
in passwd and shadow file
removing the user line and the user no longer exist
03.03. Modifying User Accounts
usermod
03.04. Removing User Accounts In Linux
userdel -r username
03.05. Managing Groups In Linux
groupadd -r
groupadd -f force group creation even exist
/etc
cat group
groupdel
groupmod -g specify new group id
groupmod -n mynewgroupname mygroup2
03.06. System Accounts And Special Purpose Accounts
cat passwd
system account
less 500 consider system account
or 1000 depends of the distribution
03.07. Password Policy With The chage Command
chage command
03.08. Password Aging
sudo apt-get install chage
sudo chage -E “2016-04-20” testuser
05.01. Lesson Hello Bash! Our First Bash Script
vi myscript
#!/bin/bashpwdcd /etc
chmod u+x myscript
backup script
#!/bin/bash tar -cvzf backup.tar.gz /home/user cp $HOME/backup.tar.gz /home/user/backupecho Backup is completed
05.02. Running Basic Commands Inside A Bash Script
vi findlist
#!/bin/bash
#list all contents in a directory and write the ouptut to a file name dir_list.txt
ls >> dir_list.txt
chmod u+x findlist
—
vi findlist2
#!/bin/bash #list all contents in a directory and write the ouptut to a file name dir_list.txt location=$1filname=$2if [ -z "$location" ]thenecho "Please provide location"exitfiif [ -z "$filename" ]thenecho "Please provide filename " exit fi ls $location > $filename echo "Script is completed and has indexed $location"echo "########"echo "Displaying contents of dir_lits.txtecho "########" cat $fiename
chmod u+x findlist2
findlist2 /var/log mylist.txt
05.03. Bash Variables and Script Arguments
vi testscript #!/bin/bash echo $HOME echo $USER variable=hello echo $variable echo " " echo " " echo $variable2345
vi pinhead #!/bin/bash name=$1 username=$2 if (( $# == 0)) comment ## if no arguments display all this then echo "##############################" echo "pinehead [arg1] [arg2]" echo "arg1 is your name" echo "arg2 is your username" exit fi
var1=”Your name is ${name} and your userbame is ${username}”
‘echo ${var1} >> yourname.txt’ comment ##>> append to file
06.01. Ifconfig-ifup-ifdown
ifconfig
sudo ifconfig eth0 down
sudo ifconfig eth0 up
lo – loopback adapter
sudo ifdown – – all bring down all interfaces also loopback adaptor
sudo ifconfig lo up
lo – is your loopback adapter
Ubuntu
cd /etc/network
cat interface
auto loiface lo inet loopback
sudo vim /etc/network/interfaces
iface eth0 inet static address 192.168.1.17 netmask 255.255.255.0 gateway 192.168.1.1
sudo /etc/init.d/network
sudo /etc/init.d/networking restart
sudo su-
cd /etc/network
vim interfaces
auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.1.17 netmask 255.255.255.0 gateway 192.168.1.1 network 192.168.1.0 broadcast 192.168.1.255 dns-nameservers 192.168.1.195
sudo reboot
ifconfig
sudo ifconfig eth0 -promisc
ssh user@CENTOS
ifconfig
ls -la /etc/sysconfig/network-scripts
ifconfig
ls -al ifcfg*
sudo vim ifcfg-eth0
ls -al /etc/init.d/net*
sudo /etc/init.d/network restart
reboot
6.02. Linux Routing Using Route Command
route
netstat -rn
sudo route add default gw 192.168.1.1
route
add a host
sudo route add -host google.com reject
sudo route -host 192.168.1.3 reject
route
route -n
sudo route del default gw 192.168.1.1.
sudo route add -net 74.125.227.0 netmask 255.255.255.0 gw 192.168.1.1
sudo route del -net 74.125.227.0 netmask 255.255.255.0 gw 192.168.1.1
06.03. Using Linux Ping
echo
port 7
ifconfig
ping -A google.com doesn’t wait for echo replay from every packet
ping -c 10 google.com count 10
sudo ping -f 192.168.1.1 sending a lot a ping request
ping -f -i 2 192.168.1.1 2 seconds
ping -n google.com without name resolution
ping -q google.com quiet response
ping -c 10 -q google.com > results.txt
sudo ping -f -i .5 -c 100 192.168.1.1. > results.txt
0.5 half seconds
06.04. -etc-resolv.conf
resolv.conf configuration dns search domains, active directory domains name resolutions
netstat -rn
route -n
ping goole.com
cat /etc/resolv.conf
sudo vim /etc/resolv.conf
nameserver 8.8.8.8 <– google dns
/etc/resolvconf
ls -al
cd resolv.conf.d/
cat base
cat head
etc/resolvconf/resolv.conf.d/
vim base
namserver 192.168.1.195
cat head && cat base
cat /etc/resolv.conf
sudo resolvconf -u <–can be dynamic rebuild anytime
/etc/resolvconf/resolv.conf.d/ vi base
base
nameserver 192.168.1.195
nameserver 8.8.8.8
domain test.local
/etc/resolvconf/resolv.conf.d/ vi head
# this was created during tutorial
sudo resolvconf -u
ping test.local
06.05. -etc-hosts
/etc/hosts
cat hosts
nslookup google.com
06.06. -etc-hostname
more /etc/issue
cat hostname
centos
cat /etc/issue
cd /etc/sysconfig
cat network
cat /etc/hosts
hostname
temporary assign name
hostname temporaryname
until reboot the system
uname -a
. 06.06. -etc-hostname
more /etc/issue
cat /etc/hosts
uname -a
06.07. -etc-nsswitch.conf
/etc/nsswitch.conf
hosts: dns file mdns
sudo /etc/init.d/network
passwd:
group:
shadow:
netgroup:
we install Name Service Cache Daemon
sudo apt-get install nscd
ls -al /etc/init.d/nscd restart
all base on authentication system
06.08. IPv4
class structure
v
06.10. IPv4 Network Range Calculation
Subnetting is the process of partitioning a network in to smaller independent networks. The resulting smaller networks are called subnets.
Subnetting is good practice in network design.
Host/Subnet Quantities Table
Class B Effective Effective # bits Mask Subnets Hosts ------- --------------- --------- --------- 1 255.255.128.0 2 32766 2 255.255.192.0 4 16382 3 255.255.224.0 8 8190 4 255.255.240.0 16 4094 5 255.255.248.0 32 2046 6 255.255.252.0 64 1022 7 255.255.254.0 128 510 8 255.255.255.0 256 254 9 255.255.255.128 512 126 10 255.255.255.192 1024 62 11 255.255.255.224 2048 30 12 255.255.255.240 4096 14 13 255.255.255.248 8192 6 14 255.255.255.252 16384 2 Class C Effective Effective # bits Mask Subnets Hosts ------- --------------- --------- --------- 1 255.255.255.128 2 126 2 255.255.255.192 4 62 3 255.255.255.224 8 30 4 255.255.255.240 16 14 5 255.255.255.248 32 6 6 255.255.255.252 64 2![]()
Prefix Format Decimal Available Host Addresses /8 255.0.0.0 16777214 /9 255.128.0.0 8388606 /10 255.192.0.0 4194302 /11 255.224.0.0 2097150 /12 255.240.0.0 1048574 /13 255.248.0.0 524286 /14 255.252.0.0 262142 /15 255.254.0.0 131070 /16 255.255.0.0 65534 /17 255.255.128.0 32766 /18 255.255.192.0 16382 /19 255.255.224.0 8190 /20 255.255.240.0 4094 /21 255.255.248.0 2046 /22 255.255.252.0 1022 /23 255.255.254.0 510 /24 255.255.255.0 254 /25 255.255.255.128 126 /26 255.255.255.192 62 /27 255.255.255.224 30 /28 255.255.255.240 14 /29 255.255.255.248 6 /30 255.255.255.252 2
07.01. Understanding System Cron
crontab -e <–edit
crontab -l
/etc
vi crontab
cd cron.daily
cron.allow < all user oin system deny access to cron except user present in cron.allow
tail -f /var/log/cron show every cron oin the systems and when runn’s
07.02. Understanding User Cron
configuration file
/var/spool/cron
07.03. Cron User Permissions
cron.deny
cron.allow
deny all user for cron tab
rm cron.deny
and create cron.allow
all user on the system deny access to cron except for those allowed
07.04. Creating Cron Jobs By Example
crontab -e
every 2 minutes
*/2 * * * * date >> minutes .txt
tail -f /var/log/cron
07.05. Using The AT utility.mp4
at schedule a task one time some time in future – one event
atq <— at queue comand list all job in queue
atrm <— remove at from queue
atrm 5 number of the job
at now +1 minute
at> /echo.sh
at noon
at teatime is 4pm
atrm
atq
08.01. Triple Tools.mp4
sudo apt-get install clamav
sudo service clamav-daemon start
sudo freshclam
sudo service clamav-daemon start
clamscan -r /home
sudo apt-get install chkrootkit
sudo chkrootkit -x | less
sudo apt-get install lsat <— utility for security concern for different module application permission
sudo cat lsat.out
sudo lsat -o custom.out -m debian -x modules.exclude^C
vim modules.exclude
tail custome.out
tail lsat.html
08.02. Securing User Accounts with John the Ripper
sudo apt-get install john john-data
download.openwall.net/pub/wordlists all.gz
john -users: -testuser -wordlist:all password.list
08.03. Using nmap And Exploring Your Network
sudo apt-get install nmap sysstat
sudo nmap localhost
sudo nmap -p1-80 localhost
sudo nmap -p22,23,80,443,389,3489,400 localhost
sudo nmap 192.168.1.0/24
sudo nmap -sP 192.168.1.0/24 > results.txt
cat results.txt | grep 192.168.1
sudo nmpa 192.168.1.250
sudo nmap -p1-340 -sV 192.168.1.250
sudo nmap -O 192.168.1.250
sudo nmap -oA scanresults.txt 192.168.1.250
cat scanresults.txtgnmap | cut -d” ” -f2 | grep ^[0-9] > newinput.txt
sudo nmap -vv -oA scanresults.txt 192.168.1..250
08.04. Wireshark
sudo apt-get install wireshark
wireshark &
08.05. Introduction To IPTables
ubuntu
ls -al /etc/init.d/ip*
which ufw
ubuntu
centos
sudo service iptable start
sudi service iptable stop
sudo iptable -L
sudo ufw enable <–enable firewall
sudo iptable -L
sudo iptable -P INPUT DROP
sudo iptable -P OUTPUT DROP
sudo iptable -P FORWARD DROP
ifconfig
ssh -l user iphost
enable ssh
sudo iptables -A INPUT -p tcp –dport 22 -j ACCEPT
sudo iptables -A OUTPUT-p tcp –sport 22 -j ACCEPT
sudo iptable -L
ls -al /var/log/ufw.log
centos
ls -al /etc/init.d/ip*
sudo service iptables start
08.06. Good Old Netstat
netstat -i interface information activ
netstat -rn
netstat -a | grep
netstat -uta utp
netstat -aute all utp tcp and extended information
netstat -lt listing application
netstat -s summary
netstat -pt program information
netstat -t
netstat -c running every few seconds
netstat -r routing information
netstat -ap | grep ssh lista ll application and port running on system
netstat -an | grep ‘:80’
netstat –tcp –listening –programs
netstat –udp –listening
08.07. Using IPTraf
sudo apt-get install iptraf rrdtool ( rrd database to colet is not necesary for iptraf)
sudo iptraf -s eth0 -B & RUNNING IN BACKGROUND
ps aux | grep iptraf
cd /var/log/iptraf
tail tcp_udp_services-eth0.log
08.08. Finding SUID and GUID Files and Directories
SUID – allows to run run access privilege files as yourself
find / -user root -perm -4000 -print
GUID
find / -group root -perm -2000 -print
find / -nouser -print | more
find / -ungroup -print | more
sudo find / -type l -ls | more
08.09. LSOF
lsof list open file
sudo lsof | more
COMMAND
PID
TID
USER
FD file descriptop
TYPE type of file
DEVICE
SIZE/OFF
NODE NAME
ps aux | grep syslog
sudo lsof /var/log/syslog
ps aux | grep <PID>
all the file under var log there are open
lsof +D /var/log
lsof -u root
lsof -u ubuntu | grep home
lsof -p 2258 useful for debuging
ps aux
lsof -p 2258
kill -9 ‘lsof -t -u username’ kill all process where user id “username” have open
09.01. Syslogd and Rsyslogd
cd /etc
ls | grep rsyslog
every file is included
09.02. Using Logger To Add Entries To Log Files
logger
logger hello will
tail messages
logger -s error message
logger -t backupscript -s error message
-t is for tag
logger -f /var
logger -t backupscript -i error while try to backup
09.03. Logrotate
ls | grep logrotate
/etc
logrotate.conf
logrotate.d
10.03. Managing Linux Time Zones
cd /etc
ls -al | localtime
ls -al | grep localtime
to change timezone
date
rm /etc/localtime
cp New_York /etc/localtime
date
chenge back
ln -s /user/share/zoneinfo/Chicago
10.04. Network Time Protocol (NTP)
service ntp status
ntpq -p
service ntp status
ntpdate
ntpq -p
11.01. LPD Legacy Interface
sudo apt-get install lpr
lpoptions-d Main
cd /etc/
more printcap
cd /etc/cups
lpstat -p
lpr -P PDF textfile.txt
cd /PDF
which lp
which lpr
lpoptions -d PDF
ps aux | grep cups
lpstat -d
11.02. CUPS Configuration and Tools
ps aux | grep cups
sudo apt-get install cups-pdf
cd /etc/cups configuration and drivers for printers
cat cups-browsed.conf – restrict Ip or networks to allow to browse or print
cat /etc/cups.conf – port listening to
/var/spool/cups
lpq
12.04. iconv and date
date –rfc-3339=date
iconv
locale
set | less
env | grep LC_ALL
12.07. Localization – LANG
13.01. ssh and known hosts
sudo apt-get install openssh-server
sudo /etc/init.d/ssh restart
/etc/init.d/sshd restart
ssh -l user@hostname
ssh -l user -v host
ssh -l user -vv host
ssh -l user -vvv host
v verbose
13.02. sshkeygen.m4v
ssh suport 2 key
create DSE key
ssh-keygen
13.01. ssh and known hosts.
sudo apt-get install openssh-server
ssh -l user@hostname
ssh -l user -v host
ssh -l user -vv host
ssh -l user -vvv host
v verbose
13.03. ssh-copy-id and Key Types.m4v
ssh-keygen -t rsa
/home/sshuser/.ssh/id_rsa
enter passphrase
/home/sshuser/.ssh/id_rsa.pub
id_dsa
id_dsa.pub
id_rsa
id_rsa.pub
know_hosts
ssh-copy-id sshuser@192.168.1.200
/.ssh/authorized_key
we can connect without pasword
ssh 192.168.1.200
enterpassphrase /home/sshusere/.ssh/id_rsa
on remote host
2 files
authorized_keys
knows_hosts
13.03. ssh-copy-id and Key Types
ssh-copy-id sshuser@192.168.0.200
remote host has autorized_key
13.04. ssh-agent and ssh-add
ssh-agent – daemon run in background
evaluate ssh agent
eval ‘ssh-agent -s’
ps aux | grep ssh
ssh-add
ssh-add -l
13.05. System RSA-DSA Keys
cd .ssh
know_hosts
ssh-keygen -t dsa
ssk*-keygen -t rsa1
/home/sshuser/.ssh/id_dsa
enter passphrase
/.ssh ll
id_dsa
id_dsa.pub
know_host
cat id_dsa.pub
13.06. PGP and GnuPGP Keys
sudo apt-get install gnupg
generate key
gpg –gen-key
enter passphrase for gpg
now generat public key
cd .gnupg
gpg –export -a “name surname” > publick.key
gpg –send-keys “realname” –keyserver hkp://subkey.pgp.net
gpg –import pubkey.txt
gpg –recv-keys email –keyserver hkp://subkeys.pgp.net
14.01. Host Security Passwd-Shadow-Nologin files
cat /etc/passwd
cat /etc/passwd | grep user
sudo cat /etc/shadow | grep user
try to crack password with john
unshadow passwd shadow
unshadow passwd shadow > combine.passwords
14.02. Host Security Init.d And Inittab file
determin the default runlevel system
/etc/inittab
ubuntu non exist anymore
/etc/init.d/
cat x11-common
for Ubuntu
vim /etc/init/rc-sysinit.conf <–
which init
which telinit
runlevel
telinit 1 single user mode non root comand
centos runlevel
14.03. Host Security Inet.d And inetd.conf
inetd starting stoping services -inetd responsible for starting services
cat /etc/services
cat /etc/services | grep ssh
ftp stream tcp nowait root /usr/sbin/ftpd ftpd < –define ftp service run over TCP started by root user and name of the daemon
sudo service inetd
14.04. Host Security Xinet.d And xinetd.conf
centos
xinetd
ps aux | grep xinet
rsync
/etc/xinet.d/ service telnet
telnet moved and connection refuse
14.05. Host Security Hosts.allow and hosts.deny
host.allow and host.deny deprecate in favor of firewall iptable ufw
host.allow is read before host.deny
cd /etc/
/etc/host.allow
ssh: LOCAL 192.168.1.195
/etc/host.deny
sudo service ssh restart
15.01. Understanding E-mail Basics
ps aux | grep postfix
yum install postfix
service postfix start
service postfix status
cd /var/mail/
ls
cat user
mail()
send mail from command line
mail -s “This si the subject” root <ENTER>
type body of the email
CTRL+D to send
cd /bin/
vi sendmail#!/bin/bashmail -s “Your script has completed thanks” < /root/bin/body.txt root
cd/root/bin
echo “this is the body of your email” > body.txt
chmod u+x sendmail
./senmail
tail -f /var/mail/root
read email from command line
mail -u root
& 4
r <–respond back
CTRL+D send
& d for delete
mailq
postqueue
postqueue -f
chkconfig –level 3 postfix on
cd /etc
vi aliases
.forward file
redirect email
16.01. Working WIth Xorg.conf Configuration File
which aticonfig
cd /etc/X11/xorg,conf
lspci | grep VGA
xorg.conf
16.02. Working With xhost
xhost
set | grep DISPLAY
export display to another system
xdpyinfo | grep display
ps aux | grep gdm
and now connecting vnc :1.0
export DISPLAY=192.168.0.18:0.0
xterm
any command run here will display on remote desktop
16.03. Using The xwininfo Utility
xwininfo -children
xwininfo -root -children
xwininfo -root -tree
xwininfo -events
xwininfo -wm
xwininfo -root -children -all
16.04. Using The xdpyinfo Utility
xdpyinfo
xdpyinfo | grep display
xdpyinfo | grep GLS
xdpyinfo | grep depth
16.05. X and startx
display manager xdm, gdm, kdm
ps aux | grep X
which xdm
which gdm
which kdm
which lightdm
which X
which startx
which xinit
cat /usr/bin/startx
xinit
cd .xinitrc
cat /etc/X11/xinit/xinitrc
./etc/X11/Xsession
16.06. Inittab and XWindows
inittab — default runlevel on the system
cat /etc/inittab
/etc/init
cat ufw.conf
cd /etc/init.d/
etc/init/rc-sysinit.conf
which telinit
runlevel
telinit
which xfs
/usr/share/
cd fonts
cd truetype/
pine tools -email