cs197u: a hands on introduction to unixtian/197u/materials/lecture4.pdfcs197u: a hands on...

36
CS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts Amherst – CICS 1

Upload: others

Post on 09-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

CS197U: A Hands on Introduction to Unix

Lecture 4: My First Linux System Tian Guo University of Massachusetts Amherst – CICS

1

Page 2: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Reminders

•  Assignment 2 was due before class

•  Assignment 3 will be posted soon

•  Please START EARLY so there is time to resolve any problems

•  As always, let me know if you are skipping an assignment

•  If you have questions, email me.

2

Page 3: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Outline

•  Last class...

•  Learned what an OS does •  Multi-tasking, resource management, and security

•  Overview of Linux file system structure

•  File permissions

3

Page 4: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Quick Quiz

•  Questions

1. What is the lowest level directory in the filesystem called?

2. What type of path starts from this directory?

3. What symbol is used to write a path relative to your home directory?

4. What types of files are stored in the /bin directory?

5. List the three types of permissions that can be set for files and directories

6. What is the Linux command for changing file permissions 4

•  Answers

1.  The root directory

2.  An absolute path

3.  ~/

4.  Executable Files

5.  Read, Write and Execute

6.  chmod

Page 5: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

•  Control access for the user, group, or “world” (everyone else)

•  “group” means everyone in the user’s group (excluding the user)

•  Abbreviation to use with chmod: g  

•  “world” means everyone who is not in the user’s group  

•  Abbreviation to use with chmod: o  

•  “all” means everyone

•  Abbreviation to use with chmod: a  

•  chmod  -­‐R  a+x  <dir>  

•  Recursively change permissions for

 all the files + dirs in <dir>

File permissions

5

u g o

a

Page 6: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Be careful when you run this command

6

•  What’s the most dangerous command you can run?

elnux3>  rm  –rf  *  

•  Removes everything in the current directory, including subdirectories

•  Without asking you for confirmation! (-­‐f  flag)

•  Depends on where you run this command

•  Run in home directory?

•  Contents of home directory are GONE!

•  Run in root / ?

•  Almost everything on the hard disk will be GONE!

•  To remove “everything” you would have to run the command with sudo  •  We will learn about sudo in this lecture

DON’T do these things!

Page 7: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Handling the processes

•  top: A dynamic real-time view of the system

•  A friendlier version: htop

•  Similar to Task Manager (Windows OS) and Activity Monitor (Mac OS)

•  ps : list the process status

•  By default: processes with terminal sessions that belongs to current user

•  ps aux: all users, all processes

•  pgrep: get the processes IDs

•  pgrep “PROCESSNAME” –l : returns both ID and name

•  Kill: send a signal to process

•  kill PROCESSID or kill -9 PROCESSID

Page 8: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Outline

•  This class:

•  Linux distributions

•  Using virtualization to run Linux on your own computer

•  Installing software in Linux

8

Page 9: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

What OS is most popular?

47%

5%

34%

5% 9%

Win7 Vista Win XP Linux Mac

Web users"source: http://www.w3schools.com

9

Aug 2015 Dec 2011

4%

20%

49%

1% 0% 4% 6%

11% 5%

Win10 Win8 Win7 Vista NT* WinXP Linux Mac Mobile

Page 10: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

What OS is most popular?

Web Servers"source: http://news.netcraft.com (spring 2010)

10

2010 2015

19%

81%

Windows Unix-Like

32%

68%

Windows Unix-Like

Page 11: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Linux distributions

•  You don’t really install “Linux” like you would for Windows OS

•  There is one Linux kernel... but lots of different Linux distributions

•  A distribution is:

•  A Linux kernel (the core OS)

•  A collection of pre-packaged applications

•  Sometimes: a window manager with graphical interface

11

Page 12: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Top distributions

•  Ubuntu - rose to popularity due to ease of use

•  Debian - Ubuntu’s parent

•  RedHat, Fedora, CentOS

•  Slackware - known for simplicity

•  Gentoo

•  FreeBSD

•  ... hundreds more

12

Page 13: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Distribution Popularity

source: http://distrowatch.com/stats.php

Mint is based on Ubuntu Av

g Hi

ts /

day

Data biased towards desktop users 13

2011

Page 14: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Distribution Popularity

source: http://distrowatch.com/stats.php

Mint is based on Ubuntu Av

g Hi

ts /

day

Data biased towards desktop users 14

2015 2881

1728 1698 1346 1236 1067

0 500

1000 1500 2000 2500 3000 3500

Page 15: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Ubuntu

•  2004: Made it easy to install Linux (nice installer, single CD)

•  Provided helpful forums and wiki

•  Pretty revolutionary compared to previous approaches...

•  Multiple CDs for Redhat

•  Gentoo compiles the entiresystem from scratch

•  Mainly designed for personal use, not for running servers

15

Page 16: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

•  Underneath, all Linux distros are very similar

•  Same Linux kernel, general libraries, basic utilities

•  Graphically, may look very different depending on the window manager

•  Gnome and KDE are the most popular window managers

•  Some software requires a specific window manager

•  generally if it starts with a G or a K...

Window Managers: Gnome vs KDE

16

Page 17: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Ubuntu Window Manager Demo

•  Unity v.s. KDE

Page 18: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Outline

•  This class:

•  Linux distributions

•  Using virtualization to run Linux on your own computer

•  Installing software in Linux

18

Page 19: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Running multiple operating systems

•  Dual Boot - install two operating systems on one computer

•  Need either two hard disks, or two disk partitions

•  If you do this, be careful

•  Install Windows first, then Linux

•  Linux will setup a “boot loader” to let you switch between OSes at startup

•  Virtualization - run a second operating system inside the first

•  The second OS is run as a Virtual Machine (VM)

•  VM tricks OS running inside it into thinking it owns the full machine

•  Can run multiple VMs at once

19

Page 20: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

•  Several different virtualization methods

•  Full Virtualization: A control program produces virtual machines

•  Used for: •  Sharing a system between multiple users •  Isolating users/systems

Virtualization

Windows or Linux

App 1 App 2

Virtualization Platform

Full Virtualization

20

Page 21: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Virtualization

•  Hosted virtualization: Operating system runs the virtualization software

•  Used for: •  Running apps for a different OS than you use •  Testing possibly unstable applications or OS

•  We will use this •  It’s easy and free

Windows

App 1

App 2

VMs

Hosted Virtualization

Windows or Linux

App 1 App 2

21

Page 22: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

•  VMware - biggest virtualization company

•  Makes both hosted and full virtualization platforms

•  Has several free versions

•  Xen - started as open source project, now part commercial

•  Runs under Linux only

•  Virtualbox - sort of open source

•  Runs in Windows, Linux, or OS X

•  Can host Windows or Linux VMs

•  KVM - for Linux only

•  Parallels - for Macs only

Virtualization platforms

22

Page 23: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Using Virtualbox

•  Available on Edlab machines in Linux only

•  Or you can install it on your own computer: http://www.virtualbox.org/

•  The VirtualBox control program lets you

•  Create new virtual machines

•  Start / Stop VMs

•  Adjust configuration •  Amount of RAM •  Disk size •  Network settings

It will ask you to register."

You can just cancel

23

Page 24: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Your first Ubuntu virtual machine

•  To create the VM, follows the guide on:

•  https://people.cs.umass.edu/~tian/197U/materials/VMsetup.html

•  Start the new VM, and watch it boot up

•  Clicking inside VM display window “captures” the mouse / keyboard

•  Press [right ctrl/cmd] key to release (varies by host operating system)

Setting up VM is part of next HW

24

Page 25: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Virtualbox DEMO

25

Page 26: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Starting with Ubuntu

•  Log in with your username and password

•  Looks around and try:

•  Change the account password: type passwd in a terminal

•  Don’t forget the new one!

•  Resources:

•  http://www.ubuntupocketguide.com/ - free guide (no pictures)

•  https://help.ubuntu.com/

•  http://library.gnome.org/users/user-guide/stable/index.html.en

26

Page 27: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Outline

•  This class:

•  Linux distributions

•  Using virtualization to run Linux on your own computer

•  Installing software in Linux

27

Page 28: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Administration: being a super user

•  In the Edlab you are a basic user

•  Limited permissions •  Can’t write outside your home directory •  Can’t install new software

•  Inside your VM, YOU are in control

•  Try not to break things... but if you do, it’s easy to restore!

•  The “root” user

•  Root is a special account for the most powerful administrator

•  If you “are root” you can do anything

28

Page 29: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Becoming “root”

•  Don’t want to use root as main account

•  Only switch to root when needed

•  Use su - “switch user” command

•  Start  root  shell:  sudo  –i  /  sudo  –s    

•  can be used with any username:    su  <username>  

•  Will ask for password!

•  Ubuntu: Don’t have to create a root account

•  Helps reduce security issues

29

Page 30: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

sudo - safely acting as root

•  Lets you run a command as if you were root

•  Does not require a root account to exist

•  You must be on the “sudoers” list to use sudo

•  Usage:  sudo  command    

•  As non-root user, will probably ask you for your password the first time

•  15 minutes password-free period

30

Page 31: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Getting software

•  How to install software?

•  In Windows or OS X, basic OS is always the same

•  Easy to add new software because dependencies are known

•  but two Linux systems may have very different configurations, drivers, libraries, etc!

•  Software repositories

•  You could build all applications from source code

•  A lot easier to use distro specific repositories •  yum, RPM, apt-get, etc

31

Page 32: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Manual Installation

•  Fetch source/binaries and install by hand

•  Advantage: customizable

•  Advantage: no limitations to what can be installed

•  Disadvantage: must manage everything

•  Disadvantage: tedious

•  First step: get the source code, usually stored as a “tar ball” •  compressed file.tar.gz or file.tgz

•  extract using tar -xzf file.tar.gz

32

Page 33: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

make - installing from source

•  make is a tool to help compile complex software

•  Typical steps to build application from source code

•  ./configure  - verifies that you have proper libraries, sets configuration

•  make - compiles all of the source code in a temporary directory •  will use things like gcc, javac, etc

•  make  install  - copies the compiled executables and libraries to their proper homes

•  Do only the last step as root!

•  otherwise bugs in the build process could corrupt important files

•  in general, don’t do something as root unless it is required

33

Page 34: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Package Managers

•  Ubuntu/Debian: apt-get

•  FreeBSD: addpkg, Redhat: rpm, Centos/Fedora: yum

•  Database of packages, requirements, etc

•  Install/update/uninstall programs fetch, install, update, and delete packages

•  Advantage: easier and faster than manual installation or compiling

•  Disadvantage: package database doesn’t have everything

•  Disadvantage: doesn’t allow customization

34

Page 35: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

apt-get - using a package manager

•  apt-­‐get  can install, remove, and provide information about software

•  To use, you must either be logged in as root, or use sudo  

ubuntu>  apt-­‐get  install  firefox  E:  Could  not  open  lock  file  /var/lib/dpkg/lock    -­‐  open  (13  Permission  denied)  E:  Unable  to  lock  the  administration  directory    (/var/lib/dpkg/),  are  you  root?    ubuntu>  sudo  apt-­‐get  install  firefox  Reading  package  lists...  Done  Building  dependency  tree  Reading  state  information...  Done  The  following  extra  packages  will  be  installed:  ...  

35

Page 36: CS197U: A Hands on Introduction to Unixtian/197U/materials/lecture4.pdfCS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System Tian Guo University of Massachusetts

Lecture 4 Review

•  There are lots and lots of Linux distributions

•  We will use Ubuntu... because it’s easy to use

•  Virtualization is an easy way to run multiple OSes on one computer

•  We will use Virtualbox... because it is free and easy to set up

•  The “Super User” root is all powerful on Linux systems

•  Ubuntu uses sudo instead of creating a root user

•  Assignment 3 will be posted soon and will be due Next Thursday 3:45PM.

36