Transcript ch5x

Text Editors
• vi is the default editor in Linux
– also called vim for vi improved
• emacs is a commonly used text editor which, to many
users is easier and more powerful
• gedit – GUI based editor
– you would not use gedit if you were logged in by text-only
(e.g., through ssh or a console not running the GUI)
• We need text editors in Linux because we often operate
with text files
–
–
–
–
system configuration files
data files
scripts
high level language programs such as C or C++ source
code)
Text Editors: vi
• Operates in different modes to differentiate
between input that is text to be placed in the
file and input that is commands
– insert – insert typed character(s) at cursor
– replace – replace typed character(s) at cursor
– command – keystrokes indicate cursor movement,
editing, repetition and file commands
From command mode to replace:
r – replace 1 character and return
R – move to replace mode
From insert or replace, <esc>
to return to command mode
vi Cursor
Movement
Commands
Text Editors: emacs
• emacs operates in one mode
– characters input are placed at the position of the
cursor
– commands are handled through control and escape
sequences
– if you have learned the Bash command line editing
shortcuts (e.g., control+a for beginning of line,
escape+f to move forward 1 word) then learning
emacs is easier because these editing shortcuts are
based on emacs control and escape sequences
Text Editors: emacs
In emacs, you can
have many buffers
open at the same
time (to make
copy and paste
easier)
Here we see two
buffers plus the
minibuffer
(used to input
commands,
filenames, etc)
Productivity Software
• Two common open source productivity software
suites are available
– LibreOffice
– OpenOffice
• Both contain similar software
–
–
–
–
–
–
Writer – word processor (like MS Word)
Calc – spreadsheet (like MS Excel)
Impress – presentation graphics (like MS PowerPoint)
Base – database management system (like MS Access)
Math – mathematical package program
Draw – drawing software
Productivity Software
A look at the main screens for OpenOffice Writer, Impress, Calc
LaTeX
• LaTeX is a non-WYSIWYG word processor
– Formatting commands are embedded in the file with
the text using \command{text} or
\begin{command}…\end{command} notation
– You must process your file to view the formatting
• latex filename creates a dvi file (device independent)
• you can then run dvipdf for instance to create a pdf from
the dvi file
– LaTeX itself calls upon a more primitive tool called
TeX
– Latex has a companion program, bibtex, to
automatically generate bibliographies
LaTeX
Command
\documentstyle
\author{author names}
\chapter{ },
\section{ },
\subsection{ },
\part{ }
\begin{tabular}{…}…
\end{tabular}
\maketitle
\newline,
\linebreak,
\nolinebreak
\parindent{ },
\textwidth{ },
\textheight{ }
\tiny, \scriptsize,
\footnotesize, \small,
\large, \Large,
\LARGE, \huge
Some LaTex sample commands
Meaning
Change type of document
Example Usage
\documentstyle[twocolumn]{book}
\documentstyle[11pt]{article}
Author names are centered in smaller font \author{Richard Fox and Frank Zappa}
under title
Create new portion of document with a \chapter{How to Use LaTeX}
title (size and numbering determined by \section{Starting Your Document}
type specified, e.g., chapter vs section)
\subsection{The title page}
Create a table where {…} indicates the \begin{tabular}{|l|lr|} {…}
justification for columns
\end{tabular}
Creates 3 columns left justified, left justified and
right justified, the use of | indicates where table
borders should be placed
Used to generate a title page
Insert new line or permit a line break at
this point, do not permit a line break
Set paragraph indentation and margins
Various text size commands
\parindent{.3in}
\textheight{1in}
LaTeX
\documentstyle{report}
\begin{document}
\begin{center}The title of the document\end{center}
\vspace{2pc}
This is a sentence. This is a second sentence. This is a third
sentence. This is a fourth sentence. This is the end of a
paragraph.
This is a new paragraph. The blank line between the two
paragraphs indicates a new paragraph. See how it automatically
indented? We can also prevent indentation.
\noindent We start a new paragraph without indentation.
another sentence for the non-indented paragraph.
And now we have another paragraph, indented.
list.
\begin{itemize}
\item The first item
\item The second item
\item The third item
\end{itemize}
This is
Lets look at a
This is much like html. We specify formatting around the
word(s) to be formatted such as {\it italicized text}, {\bf bold
faced font}, or \underline{underlined text}.
\end{document}
Sample LaTeX file (left)
and the document
produced (below)
Encryption
• Taking information and placing it into a coded
form that cannot be easily understood
• Good encryption requires a brute-force
approach to try to break the code
– Best encryption algorithms require supercomputers
1018 years to break!
• The two general forms of encryption
– symmetric key encryption (private key encryption)
– asymmetric key encryption (public key encryption)
Encryption
• Symmetric key encryption
– a private key used for both encrypting and decrypting
• Asymmetric key encryption
–
–
–
–
private key to decrypt messages
private key to generate a public key
public key to encrypt messages
public key can be made available to anyone without being a security
risk
Example Public Key
• Generated by the RSA algorithm (as used to
generate digital certificates)
b0
7c
78
aa
f5
6a
dd
43
7b
e0
eb
50
ff
e2
e6
2a
78
ca
3e
15
02
ea
bf
1a
e3
20
ae
dc
19
8c
c1
bf
99
84
52
e8
be
38
b0
98
6d
a3
87
5e
2b
f6
9d
70
86
ae
20
2e
51
20
ff
79
88
39
27
a4
6d
36
40
59
0e
3c
67
26
63
b2
a5
93
42
83
0e
8b
76
32
ac
c1
a2
af
ac
85
1e
3b
85
a0
3f
b9
54
6b
64
6b
2d
ce
73
38
5b
81
3c
b6
5d
5f
25
5b
8f
4b
73
9a
74
c6
23
88
73
bc
db
ee
b4
e0
d4
28
b4
dc
da
79
c3
c3
d4
28
98
56
df
75
41
67
ee
a3
48
a6
0c
cc
be
a2
5a
99
6c
e4
d7
54
fe
6c
be
93
0c
f3
87
d2
ea
c8
c3
8d
32
bc
00
84
dd
95
68
6d
9a
34
07
3b
5c
45
49
2d
55
80
5d
f9
3d
fa
68
a1
54
be
2b
93
73
5f
eb
58
c9
63
5a
a6
d9
3e
ac
bd
f4
77
9a
6f
65
ba
b1
13
70
db
b9
ca
2a
7a
ad
76
5d
59
37
1a
01
67
36
b1
d1
4e
e5
38
e1
ae
ac
0a
8e
22
3a
4d
29
3d
8c
97
d9
d7
7b
70
30
71
60
e3
37
88
d0
6c
b1
0f
The size of
a key is indicated
by its bit length
A hard to break
Code requires
A key of at least
256 bits
Encryption: openssl
• Many open source programs available in Linux
for encrypting/decrypting messages and
generating keys and certificates
– We look at openssl
• many different types of codes (ciphers)
– AES, DES, IDEA, RC5, Triple DES
• several different types of encryption hash functions
–
–
–
–
MD5, SHA-1, SHA-2, MDC-2
hash function uses modulo (mod) operator
used to take variable sized input and reduce it to a fixed size length
for instance, reduce any person’s name to an integer between 0 and
1000 (1001 elements, a prime number)
• supports both DSA and RDA algorithms
Encryption: openssl
• To obtain help: openssl help or openssl –h
• To encrypt a file:
– openssl enc cipher –in filename –out filename2
• cipher is the cipher name
• filename is the file to be encrypted
• filename2 is the encrypted version
– you will be asked for a passphrase interactively
• the passphrase is needed to decrypt the message
• or add –pass pass:passphrase to the command
• To view ciphers available:
– openssl list-cipher-commands
Encryption: openssl
• To generate a private key
– select the algorithm and passphrase
• Let’s assume we want to use RSA and a 2048 bit key
– openssl genrsa –out mykey.key 2048 –passout passphrase
• The following is a 128 bit key stored in mykey.key
-----BEGIN RSA PRIVATE KEY----MGICAQACEQDNctpZY1qIZUDJWhrFdownAgMBAAECEET6rv0cMqVgXwjwipD+L+EC
CQD6mQIPqBDcYwIJANHgrXHN21JtAggfZ49nkONUCwIJAIbd/Fb/VArZAggGaPTtzAuzkg==
-----END RSA PRIVATE KEY-----
• To generate a public key from the private key use
– openssl rsa –in mykey.key –pubout > mykey.pub
• without redirection, the key is output to the terminal window, the
following would be mykey.pub
-----BEGIN PUBLIC KEY----MCwwDQYJKoZIhvcNAQEBBQADGwAwGAIRAMbqZr43A+UEI/Aio2r0dKkCAwEAAQ==
-----END PUBLIC KEY-----
Encryption: openssl
• To generate a digital certificate (using x509)
– openssl req –x509 –new –key mykey.key –days 365
–out mycert.pem
• uses mykey.key private key previously generated
• outputs the certificate into the file mycert.pem, and sets the
certificate to expire in 365 days
– We are now asked a series of questions interactively
• our answers are placed in the certificate
Country Name (2 letter code) [XX]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server’s hostname) []:
Email Address []:
Encryption: openssl
Our certificate (excluding the public key, omitted because of space)
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
99:d0:2f:8c:d2:ec:cd:a9
Signature Algorithm: sha1WithRSAEncryption
Issuer: C=US, ST=Kentucky, L=Highland Heights,
O=ZappaFrank Industries, OU=Sales,
CN=ns1.zappafrank.com/[email protected]
Validity
Not Before: Feb 14 13:08:12 2013 GMT
Not After : Feb 14 13:08:12 2014 GMT
Subject: C=US, ST=Kentucky, L=Highland Heights, O=ZappaFrank
Industries, OU=Sales,
CN=ns1.zappafrank.com/[email protected]
Email Programs
• Default email client called mailx but will respond
to mail or Mail
– Others include elm, pine, Mozilla Thunderbird, Balsa
– Note: these are clients used by users to read and send
emails
– Default email server is sendmail
• To send email
– mail username(s)
– this places you in a buffer to enter the subject and then
body of the email until you press control+d
• alternatively mail username(s) –s subject
Email continued
• To view your email, enter mail
– You will see one of the two below
No mail for username
Heirloom Mail version 12.4 7/29/13. Type ? for help.
“var/spool/mail/username”: 5 messages 2 new 2 unread
1 marst Fri Jul 26 4:41 20/801 “weekend”
U 2 zappaf Mon Jul 29 10:53 20/726 “missing document”
U 3 marst Mon Jul 29 11:13 43/1831 “lunch?”
N 4 zappaf Mon Jul 29 12:41 22/1011 “missing document”
N 5 root Mon Jul 29 1:31 17/683
Email continued
• To read your email at the prompt, the possible
actions are:














<enter> - read the first new email
# - read the email numbered #, for instance entering 2 would read the email from
marst
h – list all emails
h #-# - list all emails numbered # to # as in h 100-120
r/reply – reply to the most recently read email
r/reply # - reply to email message with the given number
s/save filename – save most recently read email to filename in current directory
s/save # filename – save email numbered # to filename
list/help – list all commands available in mail
fwd/forward username – forward most recently read email to username
fwd/forward # username – forward email numbered # to username
d/delete - delete most recent email
d/delete # - delete email numbered #
q/quit – exit interactive mail
Network Software: IP Addressing
• TCP/IP primarily uses IPv4 addresses
– 32 bit number written as 4 8-bit octets separated by
periods
• 00001010.00001011.11011001.001100111
• 10.11.233.55
– The domain name system (DNS) uses servers to
translate IP aliases into addresses
– An alias that is not known by a particular DNS
name server is passed onto another server
recursively until it reaches the highest level name
servers in which case, if the name cannot be
resolved an error is returned
Network Software: Protocols
• There are a number of protocols implemented in
TCP/IP
–
–
–
–
TCP, UDP – two forms of packets
HTTP, FTP – two forms of file transfer
HTTPS, FTPS, SFTP – secure forms of file transfer
SSL – secure form of communication between client and
remote host
– DNS – IP alias to address mapping
• Programs available that implement these protocols
include
– ping, traceroute – test network connectivity and remove
host availability
– telnet, ssh, rsh – control of remote host, only ssh is secure
– ftp, sftp, http, https, ftps, wget – file transfer
– nslookup, dig, host – request for DNS name resolution
Network Software: Remote Access/FTP
• Text-based or GUI
• Establish connection first
– Requires an account on remote host
– Or you can log in anonymously
• anonymous login restricts access to public areas only
and you may not be able to upload
• Upload/download files
• There used to be many ftp servers
– With web servers available, most FTP sites have
changed to web sites although they might
accommodate both HTTP and FTP
Network Software: FTP
FTP Command
ascii
binary
cd
close
delete
get
help
lcd
ls, mkdir, pwd
mget
mput
open
put
quit
Meaning
Transfer files in ascii text (default mode)
Transfer files in binary (necessary if files are binary files)
Change directory on remote machine
Close connection but remain in ftp
Delete remote file
Transfer file from remote computer to local computer (download)
Get list of commands
Change directory on local computer so uploads originate from the
specified directory, downloads are saved to the specified directory
List contents of remote directory, create new directory on remote
machine, output current working directory on remote machine
Mass get – used in conjunction with wildcards, e.g., mget *.txt
Mass put
Open a new connection to specified machine
Transfer file from local computer to remote computer (upload)
Close connection and exit ftp
Network Software: wget
• Non-interactive form of file transfer
– Used to get files from web servers (not FTP
servers)
• format: wget URL
– Options include
• -A – allow for wildcards as in
– wget –A .jpg www.nku.edu/~foxr
• -r – recursive get – download this file and all files that
this page links to (used for a web crawler)
Network Software: Inspection
• route – display router table
• ip – many forms used to display or alter network information
including IP addresses of interface(s), routers, tunnels and more
– we look at this more closer in chapter 12
• ss – display statistics on network socket usage
• netstat – information on network connections, routing tables and
other
• ping – send packets to a remote host, display successful
connections and time to delivery
• traceroute – like ping but report on route taken to remote host
• host – display DNS table information for specified IP
alias/address as reported by host’s DNS authority
• dig – same as host
• nslookup – perform IP alias to address resolution
Network Software: ping example
• Response from ping
– ping somehost
• 64 bytes from 1.2.3.4: icmp_seq=1 ttl=60 time=0.835 ms
• 64 bytes from 1.2.3.4: icmp_seq=2 ttl=60 time=0.961 ms
• 64 bytes from 1.2.3.4: icmp_seq=3 ttl=60 time=1.002 ms
– Control+c to exit ping displays the following summary
• 3 packets transmitted, 3 received, 0% packet loss, time
2798ms rrt min/avg/max/mdev = 0.835/0.933/1.002/0.071
Network Software: nslookup example
$ nslookup www.nku.edu
Server:
172.28.102.11
Address: 172.28.102.11#53
$ nslookup www.google.com
Server:
172.28.102.11
Address: 172.28.102.11#53
canonical name = hhilwb6005.hh.nku.edu. Non-authoritative answer:
www.google.com
hhilwb6005.hh.nku.edu
canonical name = www.l.google.com.
172.28.119.82
Name:
www.l.google.com
Address: 74.125.227.51
Name:
www.l.google.com
Address: 74.125.227.49
Name:
www.l.google.com
Address: 74.125.227.48
[additional addresses omitted]
$ nslookup www.centos.com
;; Got recursion not available from 172.28.102.11, trying next server
;; Got recursion not available from 172.28.102.13, trying next server
Server:
10.11.0.51
Address: 10.11.0.51#53
www.nku.edu
Name:
Address:
Non-authoritative answer:
Name:
www.centos.com
Address: 87.106.187.200
Network Software: dig example
$ dig –t NS www.nku.edu
; <<>> DiG 9.7.3-P3-RedHat-9.7.3-8.P3.el6_2.1 <<>> -t NS www.nku.edu
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57418
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.nku.edu.
;; ANSWER SECTION:
www.nku.edu.
3600
IN
NS
IN
CNAME
;; Query time: 1 msec
;; SERVER: 172.28.102.11#53(172.28.102.11)
;; WHEN: Tue Aug 28 14:23:32 2012
;; MSG SIZE rcvd: 57
hhilwb6005.hh.nku.edu.
Network Software: host example
$ host –d www.nku.edu
Trying "www.nku.edu"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2258
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.nku.edu.
;; ANSWER SECTION:
www.nku.edu.
hhilwb6005.hh.nku.edu. 3600
3600
IN
IN
A
IN
A
CNAME
hhilwb6005.hh.nku.edu.
172.28.119.82
Received 73 bytes from 172.28.102.11#53 in 2 ms
Trying "hhilwb6005.hh.nku.edu"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 84
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;hhilwb6005.hh.nku.edu.
IN
;; AUTHORITY SECTION:
hh.nku.edu.
3600
IN
37369675 900 600 86400 3600
AAAA
SOA
[other details omitted]
Received 104 bytes from 172.28.102.11#53 in 3 ms
nkuserv1.hh.nku.edu. postmaster.exchange.nku.edu.