Professional Documents
Culture Documents
Introduction To Linux
Introduction To Linux
Introduction To Linux
1
OUTLINE
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
administe
r security
manage
memory
control a
network
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?
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
NetWare
Designed for
client/server
networks
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.
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?
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
56
Working with Linux
57
Software 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.
64
Subdirectories
/root directory, starting point of the directory tree
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
84
Shut Down
Unity desktop’s
equivalent to the
Window’s Start
button
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
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
105
Process Management
• Process is a unit of running program.
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
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.
110
Text Editor
#!/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”
112
Foreground and Background
• To run programs in background mode, use “&”
[nomura@ssc-1]$ command &
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
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
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
132
Bash
• Define a variable
– ABC=“This is test”
– 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, ...
• 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
• Routing
– route add -net 192.168.0.0/24 gw 10.10.10.2 dev eth0
142
Networking
• DNS
– /etc/resolve.conf
– /etc/hosts
• Host Name
– hostname
– /etc/hostname
144
Using from Network
• Remote shell: telnet, ssh
• Remote file transfer: ftp, lftp, sftp, scp
• Web: lynx, firefox
– Download: wget, crul, prozilla
• 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
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