Introduction to UNIX and SFTP
Introduction to UNIX
1. What is it? 2. Philosophy and issues 3. Using UNIX 4. Files & folder structure
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
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
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?
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
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)
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
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
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
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
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
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.
§ 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
~
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/...
• 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
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
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
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
§ Exercise: name the paths to all 6 files in the following diagram
UNIX
~
dir3
dir2 dir1 file1
file3 dir4
file6
file2
file4 file5
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
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
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
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
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)
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)
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)
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)
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
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 ?
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
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
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
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)
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
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
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)
Transferring files and folders
§ Drag and drop from one window to the other
§ The bottom window shows the status of the transfer
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
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
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)
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
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
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!