Introduction To Linux

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 150

INTRODUCTION TO LINUX

Department of Computer Science


UNZA

1
OUTLINE

• What is open-source software (OSS)?


• Importance and benefits of open source
• Common FUDs on OSS
• Introduction to LINUX
• Distributions
• LINUX verses WINDOWs
• The Command Line
2
What is Open-Source Software?
Free Software
Freedom to run, copy, distribute, study, change and improve
the software.
• Freedom to run the program, for any purpose
• Freedom to study how the program works, and adapt it to
your needs
• Freedom to redistribute copies so you can help others
• Freedom to improve the program, and release your
improvements to the public
Access to the source code is needed to realise most of the
above.
Open-Source Software (OSS)

Term "free" can lead to negative marketing connoctations


especially to business and corporate users.

[How can anything be good if it is free (i.e. has no monetary


value to it)?]

Term open-source software was coined to refer to free


software.
Other Categories of Software
Freeware - Non-chargeable copyrighted software
Shareware - Software delivered without charge but
continued usage subject to payment
Proprietary Software - non-Free Software
Public domain Software - non-copyrighted

Reference:
Free Software Foundation
www.fsf.org
Relationships Among the Categories

Source: http://www.fsf.org/philosophy/categories.html
Free/Open-Source Software
Licensing
Free/Open-Source software licensing falls
into 2 main types:

• Copylefted
• Non-copylefted
Copylefted Software
What is there to stop someone from converting a free
software to non-free software?
Copyleft is used to prevent this.
• Copyright a software and add in certain distribution
restrictions to prevent conversion into non-free.
• Anyone who redistributes the software, with or without
changes, must pass along the freedom to further copy and
change it.
• Guarantees that every user has freedom.
• E.g. GNU General Public License (GPL) - free software and
copyleft license
• Linux is distributed under a GNU GPL license.
Non-copylefted Software
• Much more permissive licensing than GPL
• Permission to redistribute and modify
• Permission to add additional restrictions to its further
distributrion and modification
This means that it is possible for someone to take
such software and make it proprietary with or
without modifications.
• e.g. X11 (and XFree86) license, BSD License, Apache
License
IMPORTANCE AND BENEFITS OF
OPEN SOURCE
Importance of Open Source
• Freedom to learn, redistribute and enhance
• Prevents single vendor and technology lock-in
• Promotion and preservation of open standards
• Peer review and feedback will lead to:
➢More robust and reliable software
➢Better security and faster bug fixes
• Promotes environment for positive competition, self-
learning, exploring and co-operation
• Benefits poorer societies - affordable and accessible
software running on affordable computers and networks
Benefits of Open Source to Developing
Countries
Promotes an environment which a society (like
Malaysia), striving to become a technology-driven
one, should have:
Ability to "look under the hood" and learn
Condusive for technical and system development
Ability to learn, innovate and invent (LIVE)
Encourages positive competition, self-help, and
mutual co-operation
Less dependence on software and technologies
where we can have no control/say
Benefits of Open Source to Zambia
Open source provides unique opportunities to:
Local developers to learn and participate in
systems software development
Build up a critical mass of good coders
Produce localised versions of software
Stimulate and build up the local software industry
Promote a research-based mind-set for both
public and private sectors
Open Source Usage - Server

15
Open Source Usage - Desktop

16
Common Fears, Uncetainties and
Doubts (FUDs) Regarding OSS
No Accountability
FUD: Developed/maintained on best effort basis,
volunteers, no single party fully accountable
Fact: Tightly knit developer community. Legally
established non-profit foundation or normal
businesses supporting the software
Fact: Most close-source software licenses come with
disclaimers - exempt the vendor from any liabilities
arising from the use and misuse of the software
Open source has basically same level of
accountability as close source!!
No Support
FUD: No technical support
Fact: Software author may not offer support but
support available from many sources:
• Local vendors
• User communtities worldwide
• Internet resources

Fact: Commercial proprietary software users still


mainly rely on local vendor for support
Not Secure
FUD: OSS insecure as source code is available
Fact: Inavailability of source code does not mean
vulnerabilities cannot be discovered - use modern
debugging and software development tools
Fact: Source code availability facilitates:
• Scrutiny by many people to flush out weaknesses
in design and code
• Independent check and 3rd party audit
Hidden Backdoors
FUD: Possibility of hidden backdoors in OSS
Fact:
• Possible but not vulnerable if download software
from well known/trustworthy sites
• Ensure software secuirty checksum corresponds
with published value
• Ability to examine source and re-compile
Fact:
• Commercial proprietary software known to ship
infected with virus and backdoor
• Backdoors possible in close source too and more
difficult to detect
Not User-friendly
FUD: UNIX-legacy - CLI, need to remember archaic
comands
Fact: Possibilly true in the past. In recent times GUI
Windowing system very much the default
interface.
Fact: User has a choice of using either GUI or CLI to
run most of the applications where applicable
OPERATING SYSTEMS
AND
UTILITY PROGRAMS
System Software
• What is system software?

Programs that Two types are


maintain operation operating systems
of computer and utility programs

Operating system (OS)


(sometimes called the platform)
coordinates all activities
among computer
hardware
resources
Operating Systems
• What are the functions of an operating system?
start the provide a user manage
computer interface programs

administe
r security
manage
memory

control a
network

establish an schedule jobs


monitor
Internet and configure
provide file performan
connection devices
management ce
and other
utilities
Operating System Functions
• What is booting?
 Process of starting or restarting a computer
 Cold boot
Turning on
computer that has
been powered off
 Warm boot
Restarting
computer that is
powered on
Operating System Functions
• What is a user interface?
 Controls how you enter data and instructions and how
information displays on screen
What is a graphical user interface (GUI)?

 User interacts with


menus and visual
images such as icons
and buttons
Operating System Functions
•What is single user/ multitasking?
 Working on two or
more programs that
reside in memory at
same time
• Foreground contains
program you are
using
• Background
contains
programs that are
running but are not
in use
Operating System Functions
What are other program management features of
operating systems?

Enables two or
multiprocessing more users to
run programs
simultaneously
Can support two
or more processors
running programs multi-user
at same time
Has duplicate
components such as
processors, memory,
fault-tolerant computer and disk drives
Continues to
operate when one
of its components
fails
Operating System Utility Programs
• What is a utility program?
 System software that performs
maintenance-type tasks
 Also called
utility
Operating System Utility Programs
• What is a file manager?
 Performs functions such as copying, renaming,
deleting, and moving files
 Image viewer
displays contents
of graphics file
when you double
click on it
Operating System Utility Programs
• What is an uninstaller?

Removes a In Windows XP,


program and uninstaller is in Add/Remove
all associated files Programs in Control Panel
Operating System Utility Programs
• What is a disk scanner?

 Detects and corrects


problems on hard disk
 Searches for and removes
unnecessary files
Types of Operating Systems
• What are three categories of operating systems?

Embedded Network

Stand-alone
Stand-Alone Operating Systems
• What is DOS (Disk Operating System)?

Developed in
early 1980s
for personal D Used command-line
computers
interface when first
O
developed, later
Hardly used today included menus
S
because it does
not offer GUI
Stand-Alone Operating Systems
• Windows Vista/ 7/ 10
 Successors to Windows XP, containing a new interface
and new / enhanced features
 Available in several
editions, grouped into
Home and Business
categories
Stand-Alone Operating Systems
• What is Mac OS X?
 Available only for computers manufactured by Apple
 Macintosh operating system has been model for most
GUIs
Stand-Alone Operating Systems
• What is UNIX?
 Used by power users because of its flexibility and power
 Most versions offer GUI
 Available for computers
of all sizes
Stand-Alone Operating Systems
• What is Linux?
 Popular, free, multitasking UNIX-type operating system
 Open-source software —
e

code is available to
public
 Both a stand-alone
and a network
operating system

Red Hat provides a version of Linux called Red Hat


Enterprise Linux.
Network Operating Systems
What are examples of network operating systems?

NetWare
Designed for
client/server
networks

Windows UNIX / Linux


Server 2003 Multi-purpose
Upgrade to Windows operating system
2000 Server
Solaris
 Version of UNIX
developed by Sun
Microsystems
 Specifically for
e-commerce
applications
Embedded Operating Systems
•What is an embedded operating system?
 Found on most mobile computers, PDAs, and other small
devices
 Windows CE is scaled-down version of Windows
Stand-Alone Utility Programs
• What is a virus?
 Potentially damaging computer program
 Affects computer without user’s knowledge

• An unusual message or image is displayed on the


computer screen
SIGNS OF • An unusual sound or music plays randomly
VIRUS • The available memory is less than what should be
INFECTION available
• A program or file suddenly is missing
• An unknown program or file mysteriously appears
• The size of a file changes without explanation
• A file becomes corrupted
• A program or file does not work properly
• System properties change
Stand-Alone Utility Programs
• What is an antivirus program?
 Identifies and removes viruses in memory, storage media,
and incoming files
 Must be updated frequently
What is
Linux?

It’s an Operating
System
What is Linux?
• Linux is a Unix clone written from scratch by Linus
Torvalds with assistance from a loosely-knit team
of hackers across the Net.
• Unix is a multitasking, multi-user computer
operating system originally developed in 1969 by
a group of AT&T employees at Bell Labs.
• Linux and Unix strive to be POSIX compliant.
• 64% of the world’s servers run some variant of
Unix or Linux. The Android phone and the Kindle
run Linux.
The Linux Philosophy
The *Nix Philosophy of Doug McIlroy
(i) Make each program do one thing well. To do a new job, build
afresh rather than complicate old programs by adding new
features.
(ii) Expect the output of every program to become the input to
another, as yet unknown, program. Don't clutter output with
extraneous information. Avoid stringently columnar or binary
input formats. Don't insist on interactive input.

(iii) Use tools in preference to unskilled help to lighten a


programming task, even if you have to detour to build the tools
and expect to throw some of them out after you've finished using
them.
What is Linux?
Linux + GNU Utilities = Free Unix

• a set of small programs


• Linux is an O/S core written by Richard
written by Linus Torvalds Stallman and others. They
and others AND are the GNU utilities.
http://www.gnu.org/
What is Unix?
• A multi-task and multi-user Operating System
• Developed in 1969 at AT&T’s Bell Labs by
– Ken Thompson (Unix)
– Dennis Ritchie (C)
– Douglas Mcllroy (Pipes - Do one thing, do it well)
• Some other variants: System V, Solaris, SCO
Unix, SunOS, 4.4BSD, FreeBSD, NetBSD,
OpenBSD, BSDI

48
What is Linux?
• A clone of Unix
• Developed in 1991 by Linus Torvalds, a Finnish graduate
student
• Inspired by and replacement of Minix
• Linus' Minix became Linux
• Consist of
– Linux Kernel
– GNU (GNU is Not Unix) Software
– Software Package management
– Others

49
WHAT IS LINUX?

• Originally developed for 32-bit x86-based PC


• Ported to other architectures, e.g.
– Alpha, VAX, PowerPC, IBM S/390, MIPS, IA-64
– PS2, TiVo, cellphones, watches, Nokia N810, NDS,
routers, NAS, GPS, …

50
Linux Has Many Distributions
PORTED TO OTHER ARCHITECTURES
eg. Alpha, VAX, PowerPC, IBM S/390, MIPS, IA-64
PS2, TiVo, cellphones, watches, Nokia N810, NDS, routers, NAS, GPS, …
Which Linux Distribution is better?
• > 300 Linux Distributions
– Slackware (one of the oldest, simple and stable distro.)
– Redhat
• RHEL (commercially support)
• Fedora (free)
– CentOS (free RHEL, based in England)
– SuSe ( based in German)
– Gentoo (Source code based)
– Knoppix (first LiveCD distro.)
– Debian (one of the few called GNU/Linux)
– UBUNTU (BASED IN SOUTH AFRICA)
53
Which Linux Distribution is better?
• Ask yourself these questions
– Is it going to be around in 5 yrs?
– Is it going to stay on top of the latest security
patches?
– Is it going to release updated software promptly?
– If I have problems, will the vendor talk to me?
• Personally, I use Ubuntu
• We will use Ubuntu (possibly along with
Redhat:)

54
How is Linux Used?
 Personal Workstation
 File and Print Server
 Internet Service Provider
 Three-tier Client/Server

55
Using Linux on Personal Computers

• Linux kernel for free


• Kernel is central component
• Kernel can be customized to user’s needs

56
Working with Linux

Graphical User Interface


• X Window System
• SuSE KDE

57
Software Applications

 OpenOffice: word processing, spreadsheets,


drawing
 Adobe Acrobat Reader
 Konqueror: The KDE File Manager and Web Browser
 Kmail: The KDE Mail Application
 Evolution: An Email and Calendar Program
 Sound Applications

58
Software Applications (continued)
 TV, Video, Radio, and Webcam
 K3b: The KDE Burning Application
 Digital Cameras
 Kooka: Scanning Application
 Graphics with the GIMP
 Shell system

59
Working with the “Shell”
 Executes user commands
 Command element
 Command name
 parameters

60
Linux Directory Structure
 Store drives
 Accessing data using folders
 Root directory:
 beginning of file system

61
Unix Overview (cont.)
Directory Structure

62
Unix Overview (cont.)
Important Directories
• /bin
– This contains files that are essential for correct operation of the system.
These are available for use by all users.
• /home
– This is where user home directories are stored.
• /var
– This directory is used to store files which change frequently, and must
be available to be written to.
• /etc
– Various system configuration files are stored here.

63
Unix Overview (cont.)
Important Directories
• /dev
– This contains various devices as files, e.g. hard disk, CD-ROM drive, etc.

• /sbin
– Binaries which are only expected to be used by the super user.

• /tmp Temporary files.

64
Subdirectories
/root directory, starting point of the directory tree

/home (private) directories of users

/devDevice files that represent hardware components

/etc Important files for system configuration

/etc/init.d Boot scripts/usr/bin Generally accessible programs

65
Why Use Linux?

• Costs less
• Stable
• Reliable
• Extremely powerful

66
LINUX VS WINDOWS

67
1. Financial Differences
2. Technical Differences
3. End-User Differences

68
Financial Differences

COST
LINUX WINDOWS
Online Downloads Free Not Available
Retail Price, CD $50 $300
Financial Differences
• Cost for Businesses
– Companies have to spend millions for licenses for
ever individual windows computer
– For Linux companies don’t have to spend anything

70
Technical Differences
Keeping up to date
–By Upgrading
–Linux upgrades faster than Windows
Compatibility
• Linux is Backward Compatible unlike
Windows

71
Technical Differences
Features Provided
Both support Dynamic Caching
Both have Multi-user Support

72
Differences
• No commercial word processor for
Linux, which matches the quality for
Windows

73
End-User Differences
• Proprietary vs. Open Source
Windows is a Proprietary Technology
Applications will only work on Windows
Linux – Open Source

74
Linux
 Complete information needed for download
 Technical help – Available on Internet (user
must be comfortable with UNIX system)
 Windows word processor is better than Linux

75
Linux vs. Windows
In The Commercial Arena
Head to head competition
Used side by side as servers
Both handled daily workload for several small
business operations
Linux with hardware disadvantage supported
a community of users 3 times size of NT’s

76
In The Commercial Arena
 System Administration – Most significant difference
 Linux – tougher environment
 Linux requires learning multi-user issues built into
Unix-file permissions
 NT – easier environment
 NT requires less effort to get a starter server up and
running
 But in NT you have to solve multi-user issues for each
and every subsystem

77
In The Commercial Arena
 NT – graphical interfaces, wizards and easy-to-grasp
metaphors
 But as server chores become more customized, NT
cannot handle it
 Linux – textual interface (with X-Window)
 But for complex jobs, Linux gives a powerful set of
tools

78
In The Commercial Arena
NT – easy for non-programmer
Linux – programmer-based culture

79
UBUNTU

• BASICS

80
Ubuntu Unity Login Screen

Desktop
Type

Multiple
User
Accounts

81
Ubuntu Linux Desktop (Unity)
Top Menu Bar and
Indicators

Dash

Quicklist

Launcher

Alt key for the HUD


82
83
Close, Minimize, Maximize buttons

84
Shut Down

Unity desktop’s
equivalent to the
Window’s Start
button

You can switch also


users

85
Overview of Unix System
Kernel & Shell
• Unix/Linux is operating system (OS).
• Unix system is described as kernel &
shell. User
• Kernel is a main program of Unix input

system. it controls hard wares, CPU,


memory, hard disk, network card Shell

etc. Kernel
• Shell is an interface between user
and kernel. Shell interprets your
input as commands and pass them
to kernel.
86
Unix Overview (cont.)
Multi-user & Multi-process
• Many people can use one machine at the same time.
File & Process
• Data, directory, process, hard disk etc (almost
everything) are expressed as a file.
• Process is an running program identified by a unique id
(PID).

87
Unix Overview (cont.)
Directory Structure
• Files are put in a directory.
• All directories are in a hierarchical structure
(tree structure).
• User can put and remove any directories on the
tree.
• Top directory is “/”, which is called slash or root.
• Users have the own directory. (home directory)
88
Unix Overview (cont.)
Normal user and Super user
• In Unix system, there is one special user for administrator,
which can do anything.
• This special user is called root or superuser.

Case Sensitivity
• Unix is case-sensitive.
• MYFILE.doc, Myfile.doc, mYfiLe.Doc are different.

Online Manual
• Unix has well-written online manuals.

89
Basic Commands
How to run commands
• Finder => Application => Utilitaires => Terminal
• When you log on Unix machine, you will see,
[someone]$
• One command consists of three parts, i.e. command
name, options, arguments.
Example)
[someone~]$ command-name optionA optionB argument1
argument2

90
Basic Commands
How to run commands
• Between command name, options and arguments,
space is necessary.
• Opitions always start with “-”
• Example:
cd ..
ls –l .bashrc
mv fileA fileB

91
Basic Commands
Commands
• ls show files in current position
• cd change directory
• cp copy file or directory
• mv move file or directory
• rm remove file or directory
• pwd show current position
• mkdir create directory
• rmdir remove directory
• less, more, cat display file contents
• man display online manual
92
Basic Commands
Commands
• su switch user
• passwd change password
• useradd create new user account
• userdel delete user account
• mount mount file system
• umount unmount file system
• df show disk space usage
• shutdown reboot or turn off machine
93
Basic Commands
1. Type following command 3. In your home directory,
in your directory. ls .bash_profile
ls cp .bash_profile sample.txt
ls –a less sample.txt (note: to quit less,
ls –la press “q”)
ls -Fa rm sample.txt
2. Make a directory
mkdir linux
4. check disk space usage
pwd
df
cd linux
df -h
pwd
cd
pwd
rmdir linux
94
Relative & Absolute Path
• Path means a position in the directory tree.
• To express a path, you can use relative path
or absolute path.
• In relative path expression, the path is not
defined uniquely, depends on your current
path.
• In absolute path expression, the path is
defined uniquely, does not depend on your
current path.
95
Absolute Path
• Address from the root
/home/linux/
~/linux
~: ~: Alt+N
• Similar to:
Lausanne University/Lausanne/Canton de
Vaud/ Switzerland/Europe/Earth/Solar
System/

96
Relative Path
• Relative to your current location
. : your current location
.. : one directory above your current location
pwd: gives you your current location

• Example
ls ./linux : lists the content of the dir linux
ls ../../ : lists everything that is two dir higer

• Similar to:
Go Left/turn right/take the TSOL/go

97
Relative & Absolute Path
• Relative Path  Ablsoute Path
pwd cd
mkdir mydir
cd . pwd
pwd cd /Users/invite
cd .. pwd
cd /Users
pwd
pwd
cd .. cd /
pwd pwd
cd cd /Users/invite
cd ~/mydir 98
Redirect, Append and Pipe
Redirect and append
• Output of command is displayed on screen.
• Using “>”, you can redirect the output from screen to a file.
• Using “>>” you can append the output to the bottom of the file.

Pipe
• Some commands require input from a file or other commands.
• Using “|”, you can use output from other command as input to
the command.
• On MacOSX, The Pipe sign: (Shift+Alt+N: franc, Alt+7)

99
Redirect, Append and Pipe
Commands
• head
– show first several lines and omit other lines.
• tail
– show last several lines and omit other lines.
• grep XXX File
– show lines matching pattern XXX in File

100
Redirect, Append and Pipe
• In home directory, type
 Use pipe.
ls -1 > sample.txt
less redirect.txt
less sample.txt grep Desk redirect.txt
• Use redirect. grep –n Desk redirect.txt
head -3 sample.txt man grep
head -3 sample.txt > tail redirect.txt | grep Desk
redirect.txt rm sample.txt
• Use append. rm redirect.txt
tail -3 sample.txt
tail -3 sample.txt >>
redirect.txt
less redirect.txt 101
Sorting
Commands
• sort
– Sorts using the first field of each line.
• -n
– Sorts considering the numeric value of the strings
• -k3
– Sorts using the third field of each line
• -rnk3
– Sorts in reverse order, using the numeric value of the third field

102
Permission
• All of files and directories have owner and
permission.
• There are three types of permission, readable,
writeable and executable.
• Permissions are given to three kinds of group.
owner, group member and others.
• Example:
– ls -l .bash_profile
– -rw-r--r-- 1 cnotred cnotred 191 Jan 4
13:11 .bash_profile
– r:readable, w:writable, x: executable
103
Permission
Command
• chmod
– change file mode, add or remove
permission
• chown
– change owner of the file
Example)
chmod a+w filename
add writable permission to all users
chmod o-x filename
remove executable permission from others
chmod a+x
Gives permission to the usser to execute a file

• u: user (owner), g: group, o: others a: all 104


Permission
• Check permission
ls –l .bash_profile
cp .bash_profile sample.txt
ls –l sample.txt

• Remove readable permission from all.


chmod a-r sample.txt
ls –l sample.txt
less sample.txt

• Add readable & writable premissions to file owner.


chmod u+rw sample.txt
ls –l sample.txt
less sample.txt
rm sample.txt

105
Process Management
• Process is a unit of running program.

• Each process has some information, like process


ID, owner, priority, etc.

Example) Output of “top” command

106
Process Management
Commands
• kill
– Stop a program. The program is specified by process ID.
• killall
– Stop a program. The program is specified by command name.
• ps
– Show process status
• top
– Show system usage statistics

107
Process Management
• Check your process.
ps
ps –u

• Check process of all


users.
top (To quit top, press
“q”)
ps –e
ps –ef

• Find your process.

ps –ef | grep cnotred


108
Text Editor
pico
• Programs & configuration files are text file.
• There are two popular text editors, vi and
Emacs.
• Although they are very powerful and useful, it
is also true that they are complicated for
beginners and difficult to learn.
• pico is an easy and simple alternative.

109
Text Editor

Commands
• Arrow-keys Move cursor
• CTRL+a Move to the beginning of the current line.
• CTRL+e Move to the end of the current line.
• CTRL+v Move forward one page.
• CTRL+y Move backward one page.
• CTRL+w Search for text.
• CTRL+d Delete the current character.
• CTRL+k Remove (cut) current line or selected text.
• CTRL+u Paste (uncut) last cut text at the cursor position.
• CTRL+o Save (output) the file.
• CTRL+x Exit Pico, saving the file.

• Autre: xemacs, emacs

110
Text Editor

• Create the file Hello


pico hello.pl

• Write hello.pl as follows.

#!/usr/bin/perl
print “Hello World\n”;

• Make il executable
chmod u+x hello.pl

• Run it!
./hello.pl
111
Foreground and Background
• Running job has two modes, “foreground” and “background”

• If program is running as “background”,


the program keeps running even after your session was closed

• If program is running as “foreground”,


Ctrl-C stop program
Ctrl-Z let program background

112
Foreground and Background
• To run programs in background mode, use “&”
[nomura@ssc-1]$ command &

• To get background job back into foreground mode, use “fg”


command.
[nomura@ssc-1]$ fg

113
Remote Login & File Transfer
• rshd, telnetd, ftpd, sshd are server program and
provide similar services, remote login & file transfer.
• The major difference is security level.
rshd < telnetd + ftpd < sshd

Commands
Client Server
• rsh & rcp
• rshd
• telnet & ftp
• ssh & scp
• telnetd & ftpd
• sshd
114
Remote Login & File Transfer

Remote login & file transfer system are based on server


and client model. client program on your machine ask
sever program certain service remote machine.

For example, telnet server provides remote login service.


ftp server provides file transfer service.

Sample client programs;


WS FTP FTP client
Internet Exploror HTTP client
Eudora POP, SMTP client

115
Quick Start
• Access to Linux
– Remote
– Local
• Remote
– Through network
– Telnet, insecure and disabled now
– SSH, Secure Shell Protocol
• Local
– Linux installation or Live CDs

116
Quick Start
• System powered on
• BIOS
• POST
• Bootloader, Grub or LiLo
– Initialize Hardware
– Kernel extraction
• Kernel
– Initialize Hardware
– Kernel data structures initialization

117
Quick Start
• System Services
• Configured Services
– network and network services
• User interface
– Graphical
• Called as X window system, it is a service
• KDE, GNOME
– Text, Shells
• Switch between them: ALT-F? and CTRL-ALT-F?
• Screen 7 is the X

118
Text vs. X
• Contrary to MS Windows
– X isn't integrated into OS
– X is just an application
• Shell
– Interactive program, interface between user and kernel
– Real power of Linux, specially for hackers and administrators
– Bash (Brown Again Shell), tsh, csh
• We study Linux Text Mode and just applications
not Kernel

119
Bash
• After successful login, you get shell prompt
– $ : user
– # : root
• There are two privilege in user space
• reset: reinitialize your screen
• Linux is case sensitive
• Autocomplete: commands and file names
– Commands in $PATH
– File name in specified path

120
Bash
• Linux is multiprocess, even in command line
– Process can be run in background
• Widecards
– * : string
– ?: a char
– []: regular expression
• IO redirection to file
–> : overwrite, 2> : overwrite by stderror
– >> : append
–< : Read input
121
Bash
• IO redirection to a process
– | : pass output of command as input to other command
– One of the main features in UNIX-like systems
– Simple commands which are piped together
• Some short-cuts
– CTRL-D: Logout, End of file
– CTRL-L: Clear Screen
– CTRL-C: Stop
– CTRL-Z: Suspend
– CTRL-E: cut to end of line
– CTRL-U: cut to start of line

122
Bash
• History for each user
• Use arrow keys
• !# : # command
• !<start_of_command>: last command started
with ...
• CTRL-R: search history
• history: see command history
• .bash_history: saved $HISTSIZE number of
command

123
Linux/shell vs. Windows/cmd
• Path separator: / not \
• File extensions have NOT any meaning
• Hidden file started by ., .bashrc, .bash_history
• End of file is CTRL-D
• New line is \n not \n\r
• Options are passed by - or --
• All system configurations are saved in text files

124
Help & Doc
• Command's builtin helps: -h or --help
• Man pages
• Info pages
• Documents in /usr/share/doc
• Info pages
– are NOT complete
– Easy to use
– info <command name> or pinfo <command name>
• whatis
125
Help & Doc
• Man pages
– Most complete documentation in Linux
– Very technical
• Title, description, see also and files
– man <man-category> file/command/function
– searched in <MANPATH>
– manpath : find out the <MANPATH>
– configuration file: /etc/manpath.conf
– man -k topic : search topic in titles = apropos
– man -K topic: search topic in body

126
Mans
 /usr/share/man
man1: User commands
man2: System libraries
man3: Programming libraries
man4: Special files
man5: File formats
man7: Misc. network protocols, ...
man8: System administration
Other mans: Application man pages
127
Internet documents
The Linux Documentation Project:
www.tldp.org
Tutorials
HOWTOs
Software home pages
Mailing lists
Everything is googlized

128
Files
• Everything in Linux is file, if it is NOT process
• Files can be
– Regular file
– Directory
– Links
– device
– named pipe, ...
• Uniform interface, open, read/write, close
• You should fully understand the Linux file structure

129
Files
• Files system
– User Space, a tree structure
– Kernel Space, VFS and file system depended drivers

• What file systems in Linux


– Kernel configuration depended
– ext2, ext3, jfs, nfs, fat, ntfs, ...
– man fs

• mkfs.ext2, mkfs.ext3, mkfs.fat, ...


– make file systems

130
Shell
• Executable applications
– Binary programs: usually in developed in C
– Scripts: shell, perl, awk, python, ...

• Shell (Bash)
– After login, your shell executes (/etc/passwd)
– .bash_profile
– /etc/bashrc
– .bashrc
131
Bash
• Environment Variables
– Save, parameters and some configurations
• Some important variables
– $PATH: Path of commands

– $HOME: Your home directory

– $SHELL: Your shell address

– $PS1: Bash prompt

– $USER: Your login name

132
Bash
• Define a variable
– ABC=“This is test”

• View variable content


– echo $ABC

• Define variable for subsequent shells


– export AAA=“This is test”

• View all variables


– printenv
133
Bash Script
• Bash programming language
– Variables
• User defined variables
• Built in variables: $0, $?, ...

– All commands

134
Bash Script

– Control statements
• for <name> in <word>; do <commands>; done
• case <variable> in x) <command>;; y) <commands>;;
esac
• if <condition>; then <commands>; elif <condition>
then <command>; fi
• while <condition>; do <commands>; done

135
Example
vim test.sh
#!/bin/bash
for file in *; do
if grep -q $1 $file; then
echo “Found in file: “ $file
fi;
done;
exit 0
chmod +x test.sh
./test.sh test
136
C programming
• GCC: GNU Compiler Collection
– C, C++, Java, ADA, Fortran, ...

• Tools to build C or C++ program


– cpp: C preprocessor
– cc: C Compiler
– c++: C++ Compiler
– as: The assembler
– ld: Linker
– gdb: GNU debugger
137
C programming
• All steps altogether
– gcc -o <output name> <input C>

• Intermediate results
– -c : Just compile, with out linking
– -S: Produce assembly code
– -E: Just process the file
– -g: Add debugging options

138
C programming (make & Makefile)
• Open source world
• Automate compiling large packages: make &
Makefile
• target : req1 req2 ....
– Rule1 to make target
– Rule2 to make target
• req1 : req11 req12
– Rule11 to make req1
– .... 139
Installing programs
• Binary format
– Distribution depended
• Red Hat & Fedora: rpm & yum
• Debian based (Ubuntu): apt-get

• Source code
./configure
make
make install
140
Networking
• Most of network protocols are implemented in Linux
– Application layer: bind, apache, sendmail, ssh, ftp, NFS
– Transport layer: TCP, UDP
– Network Layer: IP, IPX, ATM
– Physical layer: PPP, Ethernet, 802.11

• Configurations
– On line
– Config files

141
Networking
• Network interface (Ethernet)
– ifconfig eth0 10.10.10.1 netmask 255.255.255.0 up

– Red Hat: /etc/sysconfig/network & networking


– Ubuntu: /etc/network/interfaces

• Routing
– route add -net 192.168.0.0/24 gw 10.10.10.2 dev eth0

– /etc/sysconfig/networking & network

142
Networking
• DNS
– /etc/resolve.conf
– /etc/hosts

• Host Name
– hostname
– /etc/hostname

• IP suit: ip route, ip address, ip route ....


143
Networking
• Monitoring and Troubleshooting
– List of all connections: netstat -an
– Find route and its MTU: tracepath, traceroute
– Check liveness: ping
– Your machine ip traffic: iptraf
– Sniffer: tcpdum, ethereal
– Scanners: nmap, amap, ...

144
Using from Network
• Remote shell: telnet, ssh
• Remote file transfer: ftp, lftp, sftp, scp
• Web: lynx, firefox
– Download: wget, crul, prozilla

• Mail: fetchmail, mail


• DNS resolver: nslookup, dig
• Windows NetBIOS: smb* commands
145
Services
• Linux services
– Network services: web, mail, ...
– Local services: udev, alsa

• Startup scripts
– /etc/init.d/<sevice name>, /etc/init.d/apache2

• Configuration files
– /etc, /etc/apache2

146
Security
• Security
– Local: File security, Process security
– Network

• SELinux: role-based access control and sandboxing


• Each user
– Has its own unique ID, /etc/passwd
– Belong to some groups, /etc/group

147
Security
• Process security
– Each process has its own user id
– You can kill only your processes, root can do
anythings

148
Network Security
• Statefull Firewall: iptables
• IDS: snort
• VPNs
– IPSec: openswan
– SSL: stunnel, openswan

• Secure services
– SSH, SSL, Tunneling
149
The End

150

You might also like