60
UNIX/ LINUX TRAINING Michael Olafusi +234-808-938- 2423

UNIX/Linux training

Embed Size (px)

DESCRIPTION

Want to put your Unix/Linux skills on steroid? Contact me at 234-808-938-2423 or [email protected]

Citation preview

Page 1: UNIX/Linux training

UNIX/LINUXTRAINING

Michael Olafusi+234-808-938-2423

Page 2: UNIX/Linux training

DAY 1 – INTRODUCTION & INSTALLATIONDAY 2 – LINUX DESKTOPS & ADMINISTRATIONDAY 3 – LINUX CLI ADMINISTRATIONDAY 4 – LINUX NETWORKING & INTERNETDAY 5 – LINUX SERVER & PROGRAMMING

Page 3: UNIX/Linux training

Introducing UNIX/Linux

Page 4: UNIX/Linux training

Linux and UNIX

• Linux is an open-source clone of UNIX, the most secure and mature operating system.

• The major difference between Linux and UNIX is that UNIX is trademarked to The Open Group, while Linux is Open-source.

• All command line tools work the same on both.• Over 90% of the supercomputers in the world run Linux. And

the 10 fastest run Linux.• Linux is the leading operating system on Servers• Linux is free and popular distributions (distros) are Ubuntu,

Fedora/Red Hat, OpenSUSE, Mandriva, Mint, ArchLinux, Slackware…

Page 5: UNIX/Linux training

Benefits of UNIX/Linux

• Low cost and very stable (some Linux servers are not rebooted for over a year, try that with Windows server!).

• Best multi-user, multitasking OS. • Most secure OS. Hence, it’s popularity as a server

OS.• Best computing power and inbuilt network

support• Fastest developing OS, with the most number of

developers.

Page 6: UNIX/Linux training

Linux Distributions

• A Linux distribution consists of the Linux kernel (actual OS) and a collection of applications– Linux Kernel– X Window System– Graphical Desktops (GNOME, KDE…)– Applications

• GNU Software is at the heart of every Linux. Besides the Linux Kernel, GNU software/utilities come next

• GNOME and KDE are the most popular graphical desktops

• Ubuntu, Mandriva, OpenSUSE, RoboLinux, Slackware, Xandros, Debian GNU, Fedora, Gentoo, Knoppix, Linspire

Page 7: UNIX/Linux training

Linux Installation

Page 8: UNIX/Linux training

Linux Installation

• Similar installation process across all distros• Live CDs, to try the Linux without installing• Setting aside Space for Linux – Root folder,

Home folder & Swap space• Most secure OS. Hence, it’s popularity as a

server OS.• Burning the Linux ISO image on DVD or making

a Bootable Flash Drive• Doing the actual installation (Ubuntu as sample)

Page 9: UNIX/Linux training

Linux Installation• Best Practice requires the following on separate partitions

– Swap – /– / boot– /home– /usr– /opt– /var

• This type of partitioning scheme comes in handy when you have problem with your hard disk

• Swap partition is used to boost your computer memory and some applications require it, even the hibernate feature on Linux requires it. Rule of Thumb is to set at 2x the RAM

Page 10: UNIX/Linux training

Installing Ubuntu

Page 11: UNIX/Linux training

Installing Ubuntu – Beginning

Page 12: UNIX/Linux training

Installing Ubuntu – Linux File system

Page 13: UNIX/Linux training

Installing Ubuntu – Creating Account

Page 14: UNIX/Linux training

Installing Ubuntu - Completed

Page 15: UNIX/Linux training

Linux Desktops

Page 16: UNIX/Linux training

Linux Desktops

• The most common Desktops are GNOME and KDE (just cosmetic differences and default programs)

• Popular GNOME distros are Ubuntu & Fedora• Popular KDE distros are Kubuntu & OpenSUSE• Opening the Terminal Windows and 6 Virtual

Consoles• Navigating the Linux File System• Linux Applications

Page 17: UNIX/Linux training

Linux File System

Page 18: UNIX/Linux training

Linux File Types• Ordinary files: These are regular files. (white/black)• Directories: These are files that contains other files and directories, and provide

pointers to them. (blue)• Symbolic links: These special files link to another file, in a different location. (Cyan)• Block and character device files: All physical devices in Linux are represented by

device files. e.g. /dev/sda (yellow)• Socket file: Provides protected inter-process networking. (Purple)• Named Pipe file: Like socket files but doesn’t use network socket semantics. (Red)• $ ls –l indicates all these types

– -rw-r--r-- ordinary file– brw-rw---- block device file– crw-rw-rw- character device file– drwxr-xr-x directory file– lrwxrwxrwx symbolic file– srw-rw-rw- socket file– prw-rw-rw- named pipe file

Page 19: UNIX/Linux training

Linux/UnixAdministration

Page 20: UNIX/Linux training

Linux Administration• Linux has become extremely easy to administer,

compared to its early days. And can be administered using GUI applications (like Windows OS) or using the Commandline Interface (CLI)

• As a professional Linux administrator, you’ll have to know how to administer the OS via the CLI

• Linux supports multi-tasking, several users using the OS simultaneously.

• By default 7 users can work simultaneously (without anyone logging out). 6 Commandline users and 1 GUI user. To switch use CTRL + ALT + F1 (F2,F3,F4,F5,F6,F7) . CTRL+ALT+F7 takes you to the GUI one

• From the GUI, you can always access the commandline via “Terminal”

Page 21: UNIX/Linux training

Linux Administration

Page 22: UNIX/Linux training

Linux – User Administration • To show the Linux distro version: $ cat /proc/version• To see Linux kernel version: $ uname –r• To add new user: #useradd michael• To view the default useradd options: # useradd –D• The options are:– -g Group– -m Home directory– -f Inactive (to set password expiry date in days)– -e Expire (to disable the user after specified number of

days)– -s Shell (user’s default login shell, usually /bin/sh)

• To delete a user: # userdel –r michael

Page 23: UNIX/Linux training

Linux – CLI Key Combination • Ctrl + A to mover the cursor to the beginning of command

line• Ctrl + C to end a running program and return the prompt• Ctrl + D to log out of the current shell session, same as exit

or logout• Ctrl + E to move cursor to the end of the command line• Ctrl + H to generate backspace character• Ctrl + L to clear the terminal• Ctrl + R to search command history• Ctrl + Z to suspend a program• Shift + PageUp or PageDown to scroll (browse buffer)• Tab to autocomplete command of filename• Tab Tab to show command completion possibilities

Page 24: UNIX/Linux training

Linux CLI useful tips• If you can’t remember a command but remember the first 2 or

more letters, type them and press Tab twice. This will list all the commands that start with those letters.

• If you can’t remember how to use a particular command, type man command e.g. man mkdir to read a comprehensive help file on using the command, mkdir.

• If you need a quick help with using the options or syntax of a command, type command --help (double hypen). e.g. mkdir --help to get a quick help guide.

• To get an easy to read manual (easier than man) on any command, type info command e.g. info mkdir

• To get a short description of what a command does, type whatis command e.g. whatis mkdir

• To get a list of commands for doing a particular task, type apropos task e.g. apropos text to get text manipulation commands/applications

Page 25: UNIX/Linux training

Linux CLI text manipulation• Use cat file.txt to display the content of file.txt on the screen• Use cat file.txt | more to display the content of file.txt one

page at a time• Use cat file.txt | less to enable scrolling. Press q to exit/end.• Use tac file.txt to display the content of file.txt in reverse• Use cat file1.txt > file2.txt to copy content of file1 to file2,

file duplication.• Use cat file1.txt >> file2.txt to append content of file1 to

file2.• Use tail -10 file.txt to display the last 10 lines in file.txt• Use head -10 file.txt to display the first 10 lines in file.txt

Page 26: UNIX/Linux training

Linux CLI file permission• All files in Linux have permissions set (or unset) for user, group and other

users. It’s indicated as –rwxrwxrwx or similar.• To display a file’s permission settings, type ls -l filename• The first character indicates the file type – ordinary file, directory…• The next 3 characters indicate the permission for the file owner (user),

then next 3 for users in the owner’s group and the last 3 for other users.• r = Read w = Write x = Execute• Easiest way to change a file’s permission is to use chmod u/g/a +/- rwx

filename e.g. chmod a+w file.txt to give everyone write permission on the file, file.txt

• You can also use numeric arguments and common ones are –– chmod 400 to give only read permission to owner– chmod 600 to give read and write permission to owner– chmod 644 to give everyone read permission and the owner write permission– chmod 775 to give everyone read + execute, owner + group read write execute

permission– chmod 777 to give everyone read write exceute permission

Page 27: UNIX/Linux training

Linux CLI execution modes• By default any command you run in the command line terminal runs

in the foreground, and locks that particular terminal session till it finishes executing.

• You can also make commands run in the background, so they don’t lock the terminal session and you can start other commands while they are still running.

• To run a command in the background, type the symbol & after the command (put a space in between)

• Only run commands that do not require user interaction in the background.

• Type and execute jobs to show commands running in the background• Whenever you run a command in the background, it is assigned a

process number, n. To refer to this (command execution) process, use %n.

• To move a command process to the foreground, type fg %n (n is the command process number)

Page 28: UNIX/Linux training

Linux Administration - Performance• To a user, performance means quick execution of

commands, while to a system administrator, it means ability to do much more. As the Administrator, you’ll have to optimize system performance for the whole system – users, programs and services.

• Issues that can impair performance are – – programs that are not optimized for the system– problem with access to disks, controllers, display, other

required interfaces– network issues affecting communication with out systems– amount of users working simultaneously on the system

Page 29: UNIX/Linux training

Linux Administration - Scheduling• There are times you will want a command or script

to run at a particular time of the day or run while you are at lunch break.

• Basically, there are three types of scheduling –– Using sleep to wait fore specified seconds before running

the command. e.g. lp file1; sleep 900; lp file2; sleep 900; lp file3 (this is to insert 15mins between each file print, to allow other users print in between)

– Using at command to run a command at a specified time.– Using cron to schedule a command or script on a

monthly, weekly, daily or hourly basis

Page 30: UNIX/Linux training

Linux Administration – Output Redirection

• Piping the output to another command using |• Redirecting output via >• Redirecting output via >> (to append)• Redirecting only errors via 2>• Redirecting standard input via <• Use tee option with | (pipe) to copy input to

standard output (terminal) and more than one output files. e.g. cat original | tee copy1 copy2

• Use tee –a to append to files. e.g. cat file.txt | tee -a file_all.txt

Page 31: UNIX/Linux training

Linux Administration – Output Manipulation

• Grep: It scans output line per line, searching for matching patterns. – All lines containing the pattern will be printed to standard

output. e.g. cat countriesandcapitals.txt | grep Nigeria– This can be reversed using the –v option.

• Sort: It allows you to sort the output lines before displaying. – Default is in alphabetical order. e.g. cat alphabets | sort– It can also sort by file size, when sorting ls output. e.g. ls

~/ -la | sort -nk 5– And when used with uniq, it can sort and filter out double

entries. e.g. sort itemlist | uniq

Page 32: UNIX/Linux training

Linux Administration – Vi(m) Editor

• vi editor is a very powerful text editor that comes pre-installed on nearly all Linux OS.

• vim is variant of vi editor, basically an improved version. Practically, it is more error tolerant than vi.

• There are two modes –– Command mode, which is the default mode. You basically

scroll through the file content or enter commands. • h moves the cursor to the left, • l moves it to the right, • k to move up, and• j to move down• dd will delete current line• :w to save (write) the changes made• :q will exit the editor• :q! will exit the editor without saving changes

Page 33: UNIX/Linux training

Linux Administration – Vi(m) Editor contd

– Text input mode. You enter this mode by pressing the Insert key. There are some basic guidelines to note -• don’t attempt to scroll or change the cursor position in this mode,

position the cursor where you want to add extra text before changing to the text input mode. The only exception is when you are using vim.

• To change to this mode pressing -– a will append, move the cursor one position to the right before

switching to the inserting mode– i will insert– o will insert a blank line under the current cursor position and move

the cursor to that line

• Vim is better, just not as pre-installed on Linux OSs as Vi.

• Run vimtutor to start a recommended 30 minutes tutorial on using vim.

Page 34: UNIX/Linux training

Linux Administration - Commands

man any_command <To view the manual for target command>pwd <Print current working directory>ls <Show files in current directory>ls –a <Show maximum information about all files, including hidden>mv source destination <Move/rename a file or directory>rm target <Delete target, could be file or directory>cp source destination <Copy file or directory>mount /dev/device_name /media/device_name <Mount filesytem>umount /media/device_name <Unmount>df –h <display all mounted filesystem and available disk space in KB, MB, GB>du <display disk usage, very useful for routine maintenance>ps – ef <List all running processes, with full details>top <Standard system monitor showing a more extensive view of all processes and system resources>nohup command & <Start a process in the background and have it keep running after you log off>~/ <Current user's home directory>ifconfig <Configure network interfaces>iwconfig <Configure wireless network interfaces>

Page 35: UNIX/Linux training

Linux Administration - Commands

ssh username@ip_address <Connect to a remote server>ping ip_address <Check to see if target is online and responding>traceroute6 ip_address <View network route to target>netstat <Network Monitor>iptables –L <View firewall rules>adduser <Create a new user>usermod <Change user privileges (be very careful with this one)>deluser <Delete user>chmod <# Change privileges over file or directory >chown user_name:group_name directory_name <Change owner of a file or directory>su username <Temporarily become a different user>users <Print usernames of logged in users>

Infact, you can administer your mysql database directly from the CLI

CREATE DATABASE databasename; <New database>CREATE USER username@localhost IDENTIFIED BY 'password'; <Create a new user>show tables; <Show database schema>

Page 36: UNIX/Linux training

Unix CommandUtilities

Page 37: UNIX/Linux training

UNIX Utilities/Commands

awk Processes filescat Displays files (and is used with other tools to concatenate files)cmp Compares two filescomm Compares sorted files, and shows differencescp Copies filescpio Copies and backs up files to an archivecut Selects characters or fields from input linesdd Copies and converts input recordsdiff Compares two text files, and shows differencesdump Backs up filesfdformat Formats a floppy disk at a low levelfile Displays the file typefind Finds files within file treefmt Formats text very simplygrep Matches patterns in a filegroff Processes embedded text formatting codes

Page 38: UNIX/Linux training

gzip Compresses or decompresses fileshead Displays the first part of a file (first 10 lines by default)ispell Checks one or more files for spelling errorsless Displays files allowing for scrolling forward and backward (pauses when screen is full)ln Creates a link to a filelpr Sends a file to a printer or printer devicels Lists file and directory names and attributesman Displays documentation for commandsmkbootdisk Creates a CD (or floppy disk on older distributions)

from which to boot a systemmkdir Creates a new directorymkfs Builds a UNIX/Linux file systemmount Mounts file systems and devicesmv Renames and moves files and directoriesnewfs Creates a new file system (used in UNIX systems in particular)

UNIX Utilities/Commands

Page 39: UNIX/Linux training

UNIX Utilities/Commands

pr Formats text files for printing and displays thempwd Shows the directory you are inrdev Queries or sets the root image devicerestore Restores files (from a dump)rm Removes filesrmdir Removes directoriessed Edits streams (noninteractive)sort Sorts or merges filestail Displays the last lines of files (last 10 lines by default)tar Copies and backs up files to a tape archivetouch Changes file modification datesuniq Displays unique lines of a sorted filewc Counts lines, words, and byteswhereis Locates information about a specific file

Page 40: UNIX/Linux training

UNIX Utilities/Commandspr Formats text files for printing and displays thempwd Shows the directory you are inrdev Queries or sets the root image devicerestore Restores files (from a dump)rm Removes filesrmdir Removes directoriessed Edits streams (non-interactive)sort Sorts or merges filestail Displays the last lines of files (last 10 lines by default)tar Copies and backs up files to a tape archivetouch Changes file modification datesuniq Displays unique lines of a sorted filewc Counts lines, words, and byteswhereis Locates information about a specific file

Page 41: UNIX/Linux training

UNIX Utilities/Commandsdate Sets and displays date and timedf Displays the amount of free space remaining on diskdu Summarizes file space usagefile Determines file typefinger Displays detailed information about users who are logged infree Displays amount of free and used memory in the systemedquota Displays user disk quotas and enables them to be changedkill Terminates a running processps Displays process status by process identification number and

namesleep Suspends process execution for a specified timetop Dynamically displays the status of processes in real timeuname Shows information about the operating systemvmstat Shows information about virtual memory usew Displays detailed information about the users who are l

ogged inwho Displays brief information about the users who are logged in

Page 42: UNIX/Linux training

UNIX Utilities/Commandstp Transfers files over a networkifconfig Sets up a network interfacenetstat Shows network connection informationnfsstat Shows statistics for Network File ping Polls another network station (using TCP/IP); great for a fast

determination about whether your network connection is workingrcp Remotely copies a file from a network computerrlogin Logs in to a remote computerroute Displays routing table information, and can be used to configure routingrsh Executes commands on a remote computershowmount Lists clients that have mounted volumes on a servertelnet Connects to a remote computer on a networktraceroute Shows the route along a network between the source device and the destination, such as from a computer to a serverwvdial Controls a modem dialer for dial-up connections over a phone

line

Page 43: UNIX/Linux training

LINUX in a Network• Linux has the most robust networking tools and

support• All the possible means of connecting to the internet

work on Linux– Digital Subscriber Line (DSL)– Cable Modem– Dial-up Networking– Wireless Internet access points

• Works seamlessly in a Local Area Network and has inbuilt security tools

• Configurable network management files/tools, located in the /etc directory.

• An arsenal of Network troubleshooting tools

Page 44: UNIX/Linux training

LINUX – Network Configuration• Linux network configuration files are –– /etc/hosts This contains addresses of hosts that can be

contacted without using an external naming service like DNS. It always contains 127.0.0.1

– /etc/resolv.conf This file configures access to a DNS server. It contains your domain name and the name server(s) to contact

– /etc/nsswitch.conf This file defines the order in which to contact different name services.

• Linux Network configuration commands include –– ifconfig to display and configure the network interfaces– ip is a newer and better command. Sample use include ip

addr show and ip route show

Page 45: UNIX/Linux training

LINUX – Network Troubleshooting• Linux network commands are –– host to display information on hosts or domains. e.g. host

www.telemit.com– ping to check if a host is alive. You can interrupt by

pressing Ctrl+C– traceroute to check the route that packets follow to a

network host. e.g. traceroute www.telemit.com– whois to lookup a specific domain information

• In addition you can install several network troubleshooting and optimizing tools for free on Linux.

Page 46: UNIX/Linux training

Linux Internet

Page 47: UNIX/Linux training

LINUX and your Internet needs• Mozilla Firefox, Konqueror, Epiphany, Chromium and

Opera Browser to access the web• Mozilla Thunderbird, Evolution, Zimbra, kontact and

Kmail to do exactly what Outlook does• Graphical FTP clients like gFTP, KFTPGrabber and

even Firefox, in addition to the commandline tool FTP

• Linux can be configured as a Mail server, web server, FTP server, call manager, CMS server or Database server. And all without buying a complex expensive software.

Page 48: UNIX/Linux training

Linux Security

Page 49: UNIX/Linux training

Linux Security - Security Framework

• Determine security requirements• Perform risk assessments• Establish a security policy• Implement a robust software + hardware

security solution• Continuously monitor and manage the

security solution

Page 50: UNIX/Linux training

Linux Security – Security Threats

• Denial of Service attacks• Unauthorized Access• Unauthorized release of confidential

information• Configuration loopholes• Network loopholes

Page 51: UNIX/Linux training

Linux Security – Security Solutions

• Authentication• Access Control• Encryption• Password policies• Firewalls• Physical security of all hardware and data• Intrusion Prevention systems• Intrusion detection systems

Page 52: UNIX/Linux training

Linux Servers

Page 53: UNIX/Linux training

Linux Servers

• Web server• FTP server• Mail server• DNS server• InterNetNews (INN) server• DB Server• SIP Server

Page 54: UNIX/Linux training

Linux Servers – File sharing

• Network File System– For sharing files with other Linux/UNIX systems (or PCs

with NFS client software)

• Samba– For file sharing and print sharing Windows systems

Page 55: UNIX/Linux training

Linux Programming

Page 56: UNIX/Linux training

Linux Programming

• Linux comes with software development tools pre-installed

• Compiling source code applications• Shell Scripting– Most powerful tool of a Linux administrator– Used to automate routine administrative tasks– Used to monitor system performance and vital directories

(especially database directories for enough free space)– Makes administration of lots of computers extremely

easy and less error-prone

Page 57: UNIX/Linux training

Linux Programming – Shell Scripting

• Bash shell scripts are the most used• A simple shell script is

#!/bin/bashclearecho "Good morning, world.“# save it as morning in any folder of choice e.g. ~/Documents # to run the script give it the executable file permission# using chmod 755 ~/Documents/morning# to run the script, type ~/Documents/morning

Page 58: UNIX/Linux training

Additional Online Resources• Introduction to Linux

http://tille.garrels.be/training/tldp/index.html• Linux Newbie Administration Guide

http://lnag.sourceforge.net/downloads/LinuxNewbieAdministratorGuide.pdf

• Bash Guide for Beginners http://tille.garrels.be/training/bash/

• Ubuntu Pocket Guide & Reference http://ubuntupocketguide.com/download_main.html

Page 59: UNIX/Linux training

INTERESTED?

Page 60: UNIX/Linux training

CALL: +234-808-938-2423E-MAIL: [email protected]