introduction to unix and sftp - university of manitobacomp1270/notes/08_unix_ftp_1up.pdf ·...

44
Introduction to UNIX and SFTP

Upload: others

Post on 17-Mar-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Introduction to UNIX and SFTP

Page 2: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Introduction to UNIX

1.  What is it? 2.  Philosophy and issues 3.  Using UNIX 4.  Files & folder structure

Page 3: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

1. What is UNIX?

§  UNIX is an Operating System (OS) •  All computers require an OS

•  The OS is a program that effectively controls a computer’s resources

•  Memory •  Hard drive and files •  Peripherals

•  Among other things, the OS allows you to launch programs, save files, and communicate with other computers

Page 4: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

What is UNIX, cont’d

§  UNIX comes in many flavours and typically runs on larger, multi-user machines, or on the machines of the technically savvy

•  Our Sun machines run SunOS and Solaris •  Mac OS X runs BSD Unix •  Many of our PCs run Linux

§  UNIX is common on Internet-based machines §  You should already have an ACN UNIX account

Page 5: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

2. Open Source/Free Software

§  Which is better, Linux or Windows? §  Should we have to pay for an OS?

•  Is it really the “Microsoft Tax”? §  What are the advantages/disadvantages

of letting everyone have access to an OS’s source code?

§  Should you use Linux?

Page 6: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

3. Using UNIX

§  Recall that in COMP 1260, you used claimid to claim your U of M mail account •  This is also your UNIX account

§  Many of the computers that run UNIX on campus are behind locked doors •  You can still use them; you don’t need a key,

just your password and a communications client

Page 7: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Connecting with telnet §  telnet is a communications client

•  Available on some Microsoft Windows platforms

•  Acts as a client for a corresponding server on another (remote) computer

Telnet client

Your computer Remote computer

(running a telnet server)

Page 8: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

A Problem with telnet §  Telnet uses the Internet to communicate with

the remote computer •  The protocols that are used on the Internet are

very good at providing robust, flexible communication

•  They do not provide secure communication, though

§  Telnet sends its packets in clear text form •  This means that information you type into telnet

(like userid’s and passwords) is vulnerable to being intercepted by someone with malicious intent

§  We want a communications client that encrypts (scrambles) our communications

Page 9: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

SSH

§  Short for Secure Shell §  It is a communications client that

encrypts its information •  If someone intercepts the packets, the

information will just be gibberish §  SSH Secure Shell for Workstations (and

Windows) is available at Software Express •  It also contains a secure FTP client

Page 10: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Using SSH client

§  Choose File – Connect §  Enter Host Name and

UMnetID •  you get another dialog

for your password §  You can save this info

as a Profile so you don’t need to type it

Page 11: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

With OS X on a Macintosh §  Use Terminal (in Utilities) §  To connect, at the prompt enter

•  ssh -l UMnetID Host§  You will be prompted for your password

Page 12: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Another Option

§  SSH is a text-only program •  You type text commands, you get text

responses

§  Recall from COMP 1260: there are graphical user interfaces to UNIX •  Many are based on X (or X-Windows) •  There are X terminals in the labs, and X

programs available on Software Express

Page 13: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

After Connecting

§  OK, I can get in. Now what? •  Regardless of whether you are using X or SSH, you

will have a window where UNIX commands can be executed

•  This command line will have a prompt such as “pollux%” or “mira%”

•  This is where you enter UNIX commands and launch programs (more later!)

•  Your UNIX account will potentially allow you to do many things. In this class we will use it to host our personal web pages.

Page 14: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

§  The UNIX environment •  Among other things, your UNIX account is

used to store directories and files •  A UNIX directory is similar to a Windows folder •  Files consist of documents, applications, and

data ~

file1

file1 file2

file2

dir2

dir1

4. Files and Folder Structure

Page 15: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

~

file1

file1 file2

file2

dir2

dir1

UNIX

•  Every UNIX directory and file can be identified by a unique path name

•  ~/file1 •  ~/dir1/file1 •  ~/dir1/dir2/...

Page 16: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

•  The tilde (~) represents your home directory •  Every UNIX user has their own home •  Name matches user id

•  At the top of the hierarchy is the root directory represented by /

UNIX

/

umable

u2 u1 u3

umbaker umchan

Page 17: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

UNIX

§  This means that all your files are on the same computer (same hard drive) as everybody else’s •  For privacy’s sake, files have permissions •  Can decide whether or not they are

accessible to others

Page 18: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

UNIX

•  When permissions allow, it is possible to access files in another user’s home directory

•  You don’t have to know exactly where; shortcut: •  ~umchan/file2

/

umable

u2 u1 u3

umbaker umchan

file2

Page 19: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

UNIX

•  Making files available on the web will require a directory known as public_html under your home directory

•  An HTML file in there called index.html will be the starting point (home page) of your site

~

index.html another.html some_dir

public_html

Page 20: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

§  Exercise: name the paths to all 6 files in the following diagram

UNIX

~

dir3

dir2 dir1 file1

file3 dir4

file6

file2

file4 file5

Page 21: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

File Types and File Transferring

1.  File types 1.  Platform Dependence (ASCII vs binary)

2.  Transferring files between platforms 3.  SFTP

1.  Uploading 2.  Auto Select 3.  Changing permissions

Page 22: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

1. File types §  There are many types of files on a computer

•  Executable (application) files •  Documents created by applications (word processor,

graphics, sound, video, etc.) •  OS files •  Library files (dll’s) •  Text files (txt, html, ps)

§  Most of them are meant to be ‘read’ by the computer or a program – these are referred to as binary files

§  Text files are meant to be read by humans

Page 23: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

File Types

ASCII Table Dec Hex Binary Value 65 41 01000001 A 67 43 01000011 C 84 54 01010100 T

01000011 01000001 01010100 (File‒ binary)

add X, Y (Machine Language

instruction)

43 41 54 File (hexadecimal)

C A T (ASCII Text)

Application Text Editor

Page 24: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Representing bytes

§  All files consist of a series of bytes •  Recall a byte consists of 8 binary digits (bits)

§  A byte is usually represented using hexadecimal (hex) digits

•  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F •  Each one represents 4 bits, so a byte is represented

by 2 hex digits •  Writing hex is often easier than writing binary •  e.g. 01011100 = 5C

Page 25: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Interpreting bytes §  Since all files are just a series of bytes, what

is the difference between binary and text files?

•  All files are made up of bytes •  In a sense, all files are binary

§  It’s in the way they are interpreted •  An application is interpreted as a series of

machine instructions •  An MS Word document is interpreted as a

description of the document’s contents •  A text file is interpreted as a sequence of

characters (typically ones from a keyboard)

Page 26: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

ASCII §  In order to interpret bytes as characters, we

use a code that maps bytes to characters •  The ASCII (American Standard Code for

Information Interchange) code is the most common

•  e.g. some characters and ASCII codes (in hex) ‘0’ (30), ‘1’ (31), … ‘9’ (39) ‘A’ (41), ‘B’ (42), … ‘Z’ (5A) ‘a’ (61), ‘b’ (62), … ‘z’ (7A) ‘!’ (21), ‘?’ (3F), ‘(‘ (28), ‘)’ (29), ‘{‘(7B), ‘|’ (7C)

Page 27: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Collating sequence §  The ASCII codes form a collating sequence

that is used to sort text alphabetically 1.  We compare two strings byte by byte 2.  When we find 2 bytes that are different, the text

string with the smaller byte is first alphabetically 3.  a string formed by adding to the end of another

string appears later alphabetically §  e.g. ‘cat’ < ‘dog’ (63 < 64)

‘see Spot’ < ‘see spot’ (53 < 73) ‘Gord’ < ‘Gordy’ (rule 3)

Page 28: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Whitespace §  Some ASCII codes represent whitespace

•  Characters that aren’t visible but control the layout of the text

•  e.g. Tab (09), Space (20), Backspace (08), CR (carriage return – go to beginning of line) (0D), NL (new line – move down a line) (0A), NP (new page) (0C)

§  In Unix, man ascii will give a table of all the ASCII codes

§  ASCII tables are available on the web (see last slide)

Page 29: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Text editors

§  A text editor like Notepad allows us to type text and store it as a sequence of ASCII bytes

§  When we open a text file, the editor interprets the bytes as ASCII characters •  Binary files can be opened in a text editor, but

the result would be mostly gibberish – most of the bytes aren’t aren’t likely meant to be interpreted as characters

Page 30: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Typing in a text editor §  What happens when we type the following

into a text editor? Hello Goodbye

§  What is the sequence of bytes stored in the

text file? •  Hello = 48 65 6C 6C 6F •  Goodbye = 47 6F 6F 64 62 79 65 •  What about ?

Page 31: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Platform dependence

48 65 6C 6C 6F 0D 0A 47 6F 6F 64 62 79 65 0D 0A

DOS/Windows

§  Unfortunately, different computers deal with Enter in different ways

•  When you type Enter, it is stored differently

48 65 6C 6C 6F 0D 47 6F 6F 64 62 79 65 0D

48 65 6C 6C 6F 0A 47 6F 6F 64 62 79 65 0A

Mac

UNIX

Page 32: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

2. Transferring files

§  Platform dependence is a problem when we want to transfer files between computers •  Binary files can be transferred without change •  Text files created on one platform cannot be

transferred to another platform without changes

Page 33: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Transferring files

§  The Internet is used to transfer millions of files every day – both binary and text •  We don’t worry about platform dependence

when using a browser because it performs the conversion of text files automatically

§  We will use Secure File Transfer Protocol (SFTP) to transfer files from our computer to a remote computer

Page 34: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

3. SFTP

§  SFTP is a secure Internet client used to transfer files between computers

•  It is aware of the platform dependence of text files and performs the conversion for us when we transfer text files.

§  We just have to tell it what sort of transfer to use for a particular file

•  Binary – transfer the bytes unchanged •  ASCII – substitute the correct character(s)

Page 35: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

SFTP Terms §  SFTP transfers files between a local

computer and a remote computer •  An SFTP client runs on the local computer •  It communicates with an SFTP server on the

remote computer •  Remote computer sometimes called a host

§  SFTP has two transfer modes •  Binary and ASCII (text)

§  Transfers to the local computer are called downloads

§  Transfers to the remote computer are called uploads

Page 36: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Secure File Transfer Client §  Connect to a host just

like SSH §  Save as a profile §  Client has 2 file

navigation windows •  left is for local

computer •  right is for remote

computer

Page 37: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

SFTP with OS X on a Macintosh §  Use FileZilla (available from Software Express)

or §  TextWrangler for text or html files

•  File / Open from FTP/SFTP Server … (downloads file from server)

•  File / Save to FTP/SFTP Server … (uploads file to server)

•  File / Save a copy to FTP/SFTP Server … (uploads a copy of the file to server)

Page 38: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Transferring files and folders

§  Drag and drop from one window to the other

§  The bottom window shows the status of the transfer

Page 39: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Auto Select §  Secure File Transfer Client can automatically

choose between binary and ASCII transfer mode

•  Based on a file’s extension §  Edit – Settings – File Transfer - Mode

•  Add extensions (e.g. .txt) to the list •  Any file with an extension from the list will be

transferred in ASCII mode •  All others are transferred in binary mode •  Be sure to choose Auto Select from the toolbar

Page 40: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

Using SFTP §  You’ll likely develop your web pages on a PC

and transfer them when they’re ready for publication

§  We can use Secure File Transfer Client to create a public_html directory and transfer our web site to our Unix account

•  Connect to ccu.umanitoba.ca (with your UMnetID)

•  Tell the client to create public_html in your home directory

•  Copy index.html and your other files into public_html

Page 41: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

File Permissions with SFTP §  By default, no one can access your web

page •  Recall that we have to make our files

readable §  You can use Secure File Transfer Client

to change the file permissions. •  right click on the file or folder and choose

Properties (more on this later)

Page 42: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

File naming conventions

§  Windows and Unix differ in their rules for naming files •  Windows file names are case insensitive

•  e.g. index.html and Index.HTML are the same •  Unix file names are case sensitive

•  e.g. index.html and Index.HTML are different •  Windows file names may contain blanks •  Unix file names may not contain blanks

Page 43: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

File naming conventions

§  Some older Windows applications may be case destructive •  i.e. file names are converted to uppercase

§  Keep these differences in mind when constructing a web site offline •  Otherwise, a web site that works fine on your

Windows computer may be broken when uploaded to a Unix web server

Page 44: Introduction to UNIX and SFTP - University of Manitobacomp1270/Notes/08_unix_ftp_1up.pdf · 2011-02-07 · What is UNIX, contʼd ! UNIX comes in many flavours and typically runs on

File naming conventions

§  File naming conventions for a web site that will be uploaded to a Unix server: •  lowercase letters (a…z) •  digits (0…9) •  dash (-) and underscore (_) •  NO BLANKS!