############################## # Day 1: Linux Fundamentals # ##############################
#####################################################
# 2021 Intro to Linux & Comptia Linux+ Exam Prep #
# By Joe McCray #
#####################################################
- Here is a good set of slides for getting started with Linux:
www.slideshare.net
- Here is a good tutorial that you should complete before doing the labs below:
site: https://app.shellngn.com/
user: [email protected]
pass: P@ssw0rd123!@#123
NOTE: Ask me for the correct password
########################
# Basic Linux Commands #
########################
---------------------------Type This-----------------------------------
cd ~
pwd
whereis pwd
which pwd
sudo find / -name pwd
/bin/pwd
cd ~/students/
mkdir yourname <---- replace 'yourname' with your first name in lowercase with no spaces or special characters please
cd yourname <---- replace 'yourname' with your first name in lowercase with no spaces or special characters please
touch one two three
ls -l t (without pressing the Enter key, press the Tab key twice. What happens?)
h (and again without pressing the Enter key, press the Tab key twice. What happens?)
Press the 'Up arrow key' (What happens?)
Press 'Ctrl-A' (What happens?)
ls
clear (What happens?)
echo one > one
cat one (What happens?)
man cat (What happens?)
q
cat two
cat one > two
cat two
cat one two > three
cat three
echo four >> three
cat three (What happens?)
wc -l three
man wc
q
info wc
q
cat three | grep four
cat three | grep one
man grep
q
man ps
q
ps
ps aux
ps aux | less
Press the 'Up arrow key' (What happens?)
Press the 'Down arrow key' (What happens?)
q
top
q
-----------------------------------------------------------------------
#########
# Files #
#########
---------------------------Type This-----------------------------------
cd ~
pwd
cd ~/students/yourname/
pwd
ls
mkdir LinuxBasics
cd LinuxBasics
pwd
ls
mkdir files
touch one two three
cp one files/
ls files/
cd files/
cp ../two .
ls
cp ../three .
ls
tar cvf files.tar *
ls
gzip files.tar
ls
rm -rf one two three
ls
tar -zxvf files.tar.gz
rm -rf files.tar.gz
zip data *
unzip -l data.zip
mkdir /tmp/yourname/
unzip data.zip -d /tmp/yourname/
-----------------------------------------------------------------------
############
# VIM Demo #
############
---------------------------Type This-----------------------------------
cd ~/students/yourname/LinuxBasics
mkdir vimlesson
cd vimlesson
vi lesson1.sh
i (press "i" to get into REPLACE mode and then paste in the lines below)
#!/bin/bash
echo "This is my first time using vi to create a shell script"
echo " "
echo " "
echo " "
sleep 5
echo "Ok, now let's clear the screen"
sleep 3
clear
---------------don't put this line in your script----------------------------
ESC (press the ESC key to get you out of REPLACE mode)
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi lesson1.sh
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi lesson1.sh
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
/echo (typing "/echo" immediately after SHIFT: will search the file for the word echo).
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi lesson1.sh
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
4 (typing "4" immediately after SHIFT: will take you to line number 4).
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi lesson1.sh
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
4 (typing "4" immediately after SHIFT: will take you to line number 4).
dd (typing "dd" will delete the line that you are on)
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi lesson1.sh
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
4 (typing "4" immediately after SHIFT: will take you to line number 4).
dd (typing "dd" will delete the line that you are on)
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
syntax on (typing "syntax on" immediately after SHIFT: will turn on syntax highlighting
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
set tabstop=5 (typing "set tabstop=5" immediately after SHIFT: will set your tabs to 5 spaces
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi .vimrc
i (press "i" to get into REPLACE mode and then paste in the lines below)
set number
syntax on
set tabstop=5
ESC (press the ESC key to get you out of REPLACE mode)
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi lesson1.sh
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
echo $MYVIMRC (typing "echo $MYVIMRC" immediately after SHIFT: will display the path to your new .vimrc file
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
-----------------------------------------------------------------------
###############
# Permissions #
###############
---------------------------Type This-----------------------------------
cd ~/students/yourname/LinuxBasics
ls -l one
-----------------------------------------------------------------------
We can determine a lot from examining the results of this command. The file "one" is owned by user "me".
Now "me" has the right to read and write this file.
The file is owned by the group "me". Members of the group "me" can also read and write this file.
Everybody else can read this file
---------------------------Type This-----------------------------------
ls -l /bin/bash
-----------------------------------------------------------------------
Here we can see:
The file "/bin/bash" is owned by user "root". The superuser has the right to read, write, and execute this file.
The file is owned by the group "root". Members of the group "root" can also read and execute this file. Everybody else can read and execute this file
The next command you need to know is "chmod"
rwx rwx rwx = 111 111 111
rw- rw- rw- = 110 110 110
rwx --- --- = 111 000 000
and so on...
rwx = 111 in binary = 7
rw- = 110 in binary = 6
r-x = 101 in binary = 5
r-- = 100 in binary = 4
---------------------------Type This-----------------------------------
ls -l one
chmod 600 one
ls -l one
sudo useradd yourname
aegisweaponssystem
sudo passwd yourname
P@$$w0rd321
P@$$w0rd321
sudo chown testuser one
aegisweaponssystem
ls -l one
sudo chgrp testuser one
aegisweaponssystem
ls -l one
id
su testuser
P@$$w0rd321
-----------------------------------------------------------------------
Here is a table of numbers that covers all the common settings. The ones beginning with "7" are used with programs (since they enable execution) and the rest are for other kinds of files.
Value Meaning
777 (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
755 (rwxr-xr-x) The file's owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
700 (rwx------) The file's owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.
666 (rw-rw-rw-) All users may read and write the file.
644 (rw-r--r--) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.
600 (rw-------) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.
Directory permissions
---------------------
The chmod command can also be used to control the access permissions for directories. In most ways, the permissions scheme for directories works the same way as they do with files. However, the execution permission is used in a different way. It provides control for access to file listing and other things. Here are some useful settings for directories:
Value Meaning
777 (rwxrwxrwx) No restrictions on permissions.
Anybody may list files, create new files in the directory and delete files in the directory.
Generally not a good setting.
755 (rwxr-xr-x) The directory owner has full access.
All others may list the directory, but cannot create files nor delete them.
This setting is common for directories that you wish to share with other users.
700 (rwx------) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.
######################
# Process Management #
######################
---------------------------Type This-----------------------------------
top
q
htop
q
ps
ps aux
ps -A
ps -A | less
ps axjf
pstree
pstree -A
pgrep bash
pgrep init
ps aux | grep apache
-----------------------------------------------------------------------
You can list all of the signals that are possible to send with kill by typing:
---------------------------Type This-----------------------------------
kill -l
sudo kill -HUP pid_of_apache
The pkill command works in almost exactly the same way as kill, but it operates on a process name instead:
pkill -9 ping
The above command is the equivalent of:
kill -9 `pgrep ping`
-----------------------------------------------------------------------
################
# Hashing Demo #
################
---------------------------Type This-----------------------------------
cd ~/students/yourname/LinuxBasics
mkdir hashdemo
cd hashdemo
echo test > test.txt
cat test.txt
md5sum test.txt
echo hello >> test.txt
cat test.txt
md5sum test.txt
echo test2 > test2.txt
cat test2.txt
sha256sum test2.txt
echo hello >> test2.txt
cat test2.txt
sha256sum test2.txt
cd ..
-----------------------------------------------------------------------
#################################
# Symmetric Key Encryption Demo #
#################################
---------------------------Type This-----------------------------------
cd ~/students/yourname/LinuxBasics
mkdir gpgdemo
cd gpgdemo
echo test > test.txt
cat test.txt
gpg -c test.txt
password
password
ls | grep test
cat test.txt
cat test.txt.gpg
rm -rf test.txt
ls | grep test
gpg -o output.txt test.txt.gpg
P@$$w0rD!@#$P@$$w0rD!@#$
cat output.txt
-----------------------------------------------------------------------
#########################################################################################################################
# Asymmetric Key Encryption Demo #
# #
# Configure random number generator #
# https://www.howtoforge.com/helping-...in-enough-entropy-with-rng-tools-debian-lenny #
#########################################################################################################################
---------------------------Type This-----------------------------------
cd ~/students/yourname/LinuxBasics/gpgdemo
echo hello > file1.txt
echo goodbye > file2.txt
echo green > file3.txt
echo blue > file4.txt
tar czf files.tar.gz *.txt
gpg --gen-key
1
1024
0
y
John Doe
[email protected]
--blank comment--
O
P@$$w0rD!@#$P@$$w0rD!@#$
P@$$w0rD!@#$P@$$w0rD!@#$
gpg --armor --output file-enc-pubkey.txt --export 'John Doe'
cat file-enc-pubkey.txt
gpg --armor --output file-enc-privkey.asc --export-secret-keys 'John Doe'
cat file-enc-privkey.asc
gpg --encrypt --recipient 'John Doe' files.tar.gz
rm -rf files.tar.gz *.txt
ls
tar -zxvf files.tar.gz.gpg
gpg --output output.tar.gz --decrypt files.tar.gz.gpg
P@$$w0rD!@#$P@$$w0rD!@#$
tar -zxvf output.tar.gz
ls
-----------------------------------------------------------------------
##############################################
# Log Analysis with Linux command-line tools #
##############################################
- The following command line executables are found in the Mac as well as most Linux Distributions.
cat – prints the content of a file in the terminal window
grep – searches and filters based on patterns
awk – can sort each row into fields and display only what is needed
sed – performs find and replace functions
sort – arranges output in an order
uniq – compares adjacent lines and can report, filter or provide a count of duplicates
##############
# Cisco Logs #
##############
---------------------------Type This-----------------------------------
cd ~/students/yourname/
mkdir security
cd security
mkdir log_analysis
cd log_analysis
wget http://45.63.104.73/cisco.log
-----------------------------------------------------------------------
AWK Basics
----------
- To quickly demonstrate the print feature in awk, we can instruct it to show only the 5th word of each line. Here we will print $5. Only the last 4 lines are being shown for brevity.
---------------------------Type This-----------------------------------
cat cisco.log | awk '{print $5}' | tail -n 4
-----------------------------------------------------------------------
- Looking at a large file would still produce a large amount of output. A more useful thing to do might be to output every entry found in “$5”, group them together, count them, then sort them from the greatest to least number of occurrences. This can be done by piping the output through “sort“, using “uniq -c” to count the like entries, then using “sort -rn” to sort it in reverse order.
---------------------------Type This-----------------------------------
cat cisco.log | awk '{print $5}'| sort | uniq -c | sort -rn
-----------------------------------------------------------------------
- While that’s sort of cool, it is obvious that we have some garbage in our output. Evidently we have a few lines that aren’t conforming to the output we expect to see in $5. We can insert grep to filter the file prior to feeding it to awk. This insures that we are at least looking at lines of text that contain “facility-level-mnemonic”.
---------------------------Type This-----------------------------------
cat cisco.log | grep %[a-zA-Z]*-[0-9]-[a-zA-Z]* | awk '{print $5}' | sort | uniq -c | sort -rn
-----------------------------------------------------------------------
- Now that the output is cleaned up a bit, it is a good time to investigate some of the entries that appear most often. One way to see all occurrences is to use grep.
---------------------------Type This-----------------------------------
cat cisco.log | grep %LINEPROTO-5-UPDOWN:
cat cisco.log | grep %LINEPROTO-5-UPDOWN:| awk '{print $10}' | sort | uniq -c | sort -rn
cat cisco.log | grep %LINEPROTO-5-UPDOWN:| sed 's/,//g' | awk '{print $10}' | sort | uniq -c | sort -rn
cat cisco.log | grep %LINEPROTO-5-UPDOWN:| sed 's/,//g' | awk '{print $10 " changed to " $14}' | sort | uniq -c | sort -rn
-----------------------------------------------------------------------
##################
# Day 1 Homework #
##################
Task Option 1: Linux Survival
-----------------------------
Do all of the exercises in Linux Survival (http://linuxsurvival.com/linux-tutorial-introduction/)
Create a word document that contains the screenshots of the quizzes NOTE: You must score a perfect 100 for all 4 quizzes
Name the word document 'YourFirstName-YourLastName-LinuxDay1-LinuxSurvival.docx' (ex: 'Joseph-McCray-LinuxDay1-LinuxSurvival.docx')
Email the document to me at joe-at-secureninja-dot-com before the start of class tomorrow
Task Option 2: Basic Shell Scripting
------------------------------------
Watch and do all of the exercises in the video
Create a word document that contains the screenshots of the tasks performed in this video
Name the word document 'YourFirstName-YourLastName-LinuxDay1-ShellScripting.docx' (ex: 'Joseph-McCray-LinuxDay1-ShellScripting.docx')
Email the document to me at joe-at-secureninja-dot-com before the start of class tomorrow
#####################################################
# 2021 Intro to Linux & Comptia Linux+ Exam Prep #
# By Joe McCray #
#####################################################
- Here is a good set of slides for getting started with Linux:
![www.slideshare.net](https://cdn.slidesharecdn.com/ss_thumbnails/linuxtraining-130710022121-phpapp01-thumbnail.jpg?width=640&height=640&fit=bounds)
UNIX/Linux training
UNIX/LINUX TRAINING Michael Olafusi +234-808-938-2423 DAY 1 – INTRODUCTION & INSTALLATION DAY 2 – LINUX DESKTOPS & ADMINISTRATION DAY 3 – LINUX CLI ADMINISTRA...
- Here is a good tutorial that you should complete before doing the labs below:
Linux Tutorial Introduction | Linux Survival
Linux Tutorial - Learn Linux the easy way
linuxsurvival.com
site: https://app.shellngn.com/
user: [email protected]
pass: P@ssw0rd123!@#123
NOTE: Ask me for the correct password
########################
# Basic Linux Commands #
########################
---------------------------Type This-----------------------------------
cd ~
pwd
whereis pwd
which pwd
sudo find / -name pwd
/bin/pwd
cd ~/students/
mkdir yourname <---- replace 'yourname' with your first name in lowercase with no spaces or special characters please
cd yourname <---- replace 'yourname' with your first name in lowercase with no spaces or special characters please
touch one two three
ls -l t (without pressing the Enter key, press the Tab key twice. What happens?)
h (and again without pressing the Enter key, press the Tab key twice. What happens?)
Press the 'Up arrow key' (What happens?)
Press 'Ctrl-A' (What happens?)
ls
clear (What happens?)
echo one > one
cat one (What happens?)
man cat (What happens?)
q
cat two
cat one > two
cat two
cat one two > three
cat three
echo four >> three
cat three (What happens?)
wc -l three
man wc
q
info wc
q
cat three | grep four
cat three | grep one
man grep
q
man ps
q
ps
ps aux
ps aux | less
Press the 'Up arrow key' (What happens?)
Press the 'Down arrow key' (What happens?)
q
top
q
-----------------------------------------------------------------------
#########
# Files #
#########
---------------------------Type This-----------------------------------
cd ~
pwd
cd ~/students/yourname/
pwd
ls
mkdir LinuxBasics
cd LinuxBasics
pwd
ls
mkdir files
touch one two three
cp one files/
ls files/
cd files/
cp ../two .
ls
cp ../three .
ls
tar cvf files.tar *
ls
gzip files.tar
ls
rm -rf one two three
ls
tar -zxvf files.tar.gz
rm -rf files.tar.gz
zip data *
unzip -l data.zip
mkdir /tmp/yourname/
unzip data.zip -d /tmp/yourname/
-----------------------------------------------------------------------
############
# VIM Demo #
############
---------------------------Type This-----------------------------------
cd ~/students/yourname/LinuxBasics
mkdir vimlesson
cd vimlesson
vi lesson1.sh
i (press "i" to get into REPLACE mode and then paste in the lines below)
#!/bin/bash
echo "This is my first time using vi to create a shell script"
echo " "
echo " "
echo " "
sleep 5
echo "Ok, now let's clear the screen"
sleep 3
clear
---------------don't put this line in your script----------------------------
ESC (press the ESC key to get you out of REPLACE mode)
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi lesson1.sh
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi lesson1.sh
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
/echo (typing "/echo" immediately after SHIFT: will search the file for the word echo).
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi lesson1.sh
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
4 (typing "4" immediately after SHIFT: will take you to line number 4).
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi lesson1.sh
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
4 (typing "4" immediately after SHIFT: will take you to line number 4).
dd (typing "dd" will delete the line that you are on)
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi lesson1.sh
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
4 (typing "4" immediately after SHIFT: will take you to line number 4).
dd (typing "dd" will delete the line that you are on)
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
syntax on (typing "syntax on" immediately after SHIFT: will turn on syntax highlighting
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
set tabstop=5 (typing "set tabstop=5" immediately after SHIFT: will set your tabs to 5 spaces
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi .vimrc
i (press "i" to get into REPLACE mode and then paste in the lines below)
set number
syntax on
set tabstop=5
ESC (press the ESC key to get you out of REPLACE mode)
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
vi lesson1.sh
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
echo $MYVIMRC (typing "echo $MYVIMRC" immediately after SHIFT: will display the path to your new .vimrc file
[SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
-----------------------------------------------------------------------
###############
# Permissions #
###############
---------------------------Type This-----------------------------------
cd ~/students/yourname/LinuxBasics
ls -l one
-----------------------------------------------------------------------
We can determine a lot from examining the results of this command. The file "one" is owned by user "me".
Now "me" has the right to read and write this file.
The file is owned by the group "me". Members of the group "me" can also read and write this file.
Everybody else can read this file
---------------------------Type This-----------------------------------
ls -l /bin/bash
-----------------------------------------------------------------------
Here we can see:
The file "/bin/bash" is owned by user "root". The superuser has the right to read, write, and execute this file.
The file is owned by the group "root". Members of the group "root" can also read and execute this file. Everybody else can read and execute this file
The next command you need to know is "chmod"
rwx rwx rwx = 111 111 111
rw- rw- rw- = 110 110 110
rwx --- --- = 111 000 000
and so on...
rwx = 111 in binary = 7
rw- = 110 in binary = 6
r-x = 101 in binary = 5
r-- = 100 in binary = 4
---------------------------Type This-----------------------------------
ls -l one
chmod 600 one
ls -l one
sudo useradd yourname
aegisweaponssystem
sudo passwd yourname
P@$$w0rd321
P@$$w0rd321
sudo chown testuser one
aegisweaponssystem
ls -l one
sudo chgrp testuser one
aegisweaponssystem
ls -l one
id
su testuser
P@$$w0rd321
-----------------------------------------------------------------------
Here is a table of numbers that covers all the common settings. The ones beginning with "7" are used with programs (since they enable execution) and the rest are for other kinds of files.
Value Meaning
777 (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
755 (rwxr-xr-x) The file's owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
700 (rwx------) The file's owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.
666 (rw-rw-rw-) All users may read and write the file.
644 (rw-r--r--) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.
600 (rw-------) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.
Directory permissions
---------------------
The chmod command can also be used to control the access permissions for directories. In most ways, the permissions scheme for directories works the same way as they do with files. However, the execution permission is used in a different way. It provides control for access to file listing and other things. Here are some useful settings for directories:
Value Meaning
777 (rwxrwxrwx) No restrictions on permissions.
Anybody may list files, create new files in the directory and delete files in the directory.
Generally not a good setting.
755 (rwxr-xr-x) The directory owner has full access.
All others may list the directory, but cannot create files nor delete them.
This setting is common for directories that you wish to share with other users.
700 (rwx------) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.
######################
# Process Management #
######################
---------------------------Type This-----------------------------------
top
q
htop
q
ps
ps aux
ps -A
ps -A | less
ps axjf
pstree
pstree -A
pgrep bash
pgrep init
ps aux | grep apache
-----------------------------------------------------------------------
You can list all of the signals that are possible to send with kill by typing:
---------------------------Type This-----------------------------------
kill -l
sudo kill -HUP pid_of_apache
The pkill command works in almost exactly the same way as kill, but it operates on a process name instead:
pkill -9 ping
The above command is the equivalent of:
kill -9 `pgrep ping`
-----------------------------------------------------------------------
################
# Hashing Demo #
################
---------------------------Type This-----------------------------------
cd ~/students/yourname/LinuxBasics
mkdir hashdemo
cd hashdemo
echo test > test.txt
cat test.txt
md5sum test.txt
echo hello >> test.txt
cat test.txt
md5sum test.txt
echo test2 > test2.txt
cat test2.txt
sha256sum test2.txt
echo hello >> test2.txt
cat test2.txt
sha256sum test2.txt
cd ..
-----------------------------------------------------------------------
#################################
# Symmetric Key Encryption Demo #
#################################
---------------------------Type This-----------------------------------
cd ~/students/yourname/LinuxBasics
mkdir gpgdemo
cd gpgdemo
echo test > test.txt
cat test.txt
gpg -c test.txt
password
password
ls | grep test
cat test.txt
cat test.txt.gpg
rm -rf test.txt
ls | grep test
gpg -o output.txt test.txt.gpg
P@$$w0rD!@#$P@$$w0rD!@#$
cat output.txt
-----------------------------------------------------------------------
#########################################################################################################################
# Asymmetric Key Encryption Demo #
# #
# Configure random number generator #
# https://www.howtoforge.com/helping-...in-enough-entropy-with-rng-tools-debian-lenny #
#########################################################################################################################
---------------------------Type This-----------------------------------
cd ~/students/yourname/LinuxBasics/gpgdemo
echo hello > file1.txt
echo goodbye > file2.txt
echo green > file3.txt
echo blue > file4.txt
tar czf files.tar.gz *.txt
gpg --gen-key
1
1024
0
y
John Doe
[email protected]
--blank comment--
O
P@$$w0rD!@#$P@$$w0rD!@#$
P@$$w0rD!@#$P@$$w0rD!@#$
gpg --armor --output file-enc-pubkey.txt --export 'John Doe'
cat file-enc-pubkey.txt
gpg --armor --output file-enc-privkey.asc --export-secret-keys 'John Doe'
cat file-enc-privkey.asc
gpg --encrypt --recipient 'John Doe' files.tar.gz
rm -rf files.tar.gz *.txt
ls
tar -zxvf files.tar.gz.gpg
gpg --output output.tar.gz --decrypt files.tar.gz.gpg
P@$$w0rD!@#$P@$$w0rD!@#$
tar -zxvf output.tar.gz
ls
-----------------------------------------------------------------------
##############################################
# Log Analysis with Linux command-line tools #
##############################################
- The following command line executables are found in the Mac as well as most Linux Distributions.
cat – prints the content of a file in the terminal window
grep – searches and filters based on patterns
awk – can sort each row into fields and display only what is needed
sed – performs find and replace functions
sort – arranges output in an order
uniq – compares adjacent lines and can report, filter or provide a count of duplicates
##############
# Cisco Logs #
##############
---------------------------Type This-----------------------------------
cd ~/students/yourname/
mkdir security
cd security
mkdir log_analysis
cd log_analysis
wget http://45.63.104.73/cisco.log
-----------------------------------------------------------------------
AWK Basics
----------
- To quickly demonstrate the print feature in awk, we can instruct it to show only the 5th word of each line. Here we will print $5. Only the last 4 lines are being shown for brevity.
---------------------------Type This-----------------------------------
cat cisco.log | awk '{print $5}' | tail -n 4
-----------------------------------------------------------------------
- Looking at a large file would still produce a large amount of output. A more useful thing to do might be to output every entry found in “$5”, group them together, count them, then sort them from the greatest to least number of occurrences. This can be done by piping the output through “sort“, using “uniq -c” to count the like entries, then using “sort -rn” to sort it in reverse order.
---------------------------Type This-----------------------------------
cat cisco.log | awk '{print $5}'| sort | uniq -c | sort -rn
-----------------------------------------------------------------------
- While that’s sort of cool, it is obvious that we have some garbage in our output. Evidently we have a few lines that aren’t conforming to the output we expect to see in $5. We can insert grep to filter the file prior to feeding it to awk. This insures that we are at least looking at lines of text that contain “facility-level-mnemonic”.
---------------------------Type This-----------------------------------
cat cisco.log | grep %[a-zA-Z]*-[0-9]-[a-zA-Z]* | awk '{print $5}' | sort | uniq -c | sort -rn
-----------------------------------------------------------------------
- Now that the output is cleaned up a bit, it is a good time to investigate some of the entries that appear most often. One way to see all occurrences is to use grep.
---------------------------Type This-----------------------------------
cat cisco.log | grep %LINEPROTO-5-UPDOWN:
cat cisco.log | grep %LINEPROTO-5-UPDOWN:| awk '{print $10}' | sort | uniq -c | sort -rn
cat cisco.log | grep %LINEPROTO-5-UPDOWN:| sed 's/,//g' | awk '{print $10}' | sort | uniq -c | sort -rn
cat cisco.log | grep %LINEPROTO-5-UPDOWN:| sed 's/,//g' | awk '{print $10 " changed to " $14}' | sort | uniq -c | sort -rn
-----------------------------------------------------------------------
##################
# Day 1 Homework #
##################
Task Option 1: Linux Survival
-----------------------------
Do all of the exercises in Linux Survival (http://linuxsurvival.com/linux-tutorial-introduction/)
Create a word document that contains the screenshots of the quizzes NOTE: You must score a perfect 100 for all 4 quizzes
Name the word document 'YourFirstName-YourLastName-LinuxDay1-LinuxSurvival.docx' (ex: 'Joseph-McCray-LinuxDay1-LinuxSurvival.docx')
Email the document to me at joe-at-secureninja-dot-com before the start of class tomorrow
Task Option 2: Basic Shell Scripting
------------------------------------
Watch and do all of the exercises in the video
Name the word document 'YourFirstName-YourLastName-LinuxDay1-ShellScripting.docx' (ex: 'Joseph-McCray-LinuxDay1-ShellScripting.docx')
Email the document to me at joe-at-secureninja-dot-com before the start of class tomorrow