60
LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

Embed Size (px)

Citation preview

Page 1: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

LIS508using Debian GNU/Linux

Thomas Krichel

2010-01-10

Page 2: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

ssh

• The main protocol we use to communicate with the server is the secure shell “ssh”.

• The server has to have ssh server software installed.

• Any rented server will have this. • Otherwise run “aptitude install openssh-

server”

Page 3: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

installing putty

• Go to your favorite search engine to search for putty.

• If you have administrator rights install the installer version.

• Since you have already installed winscp, you should have no further problems.

Page 4: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

putty options

• In the window/translation choose UTF-8, always.

• Find out what the size of your screen for the font that you are using, and save that in your session.

• For wotan, the port is 22, ssh.• You can choose to disable the annoying

bell.

Page 5: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

how is ssh secure

• ssh uses public key cryptography.• It can cope with serveral crytographic

algorithm. The most common one is rsa.• In public key cryptography, you have two

keys.• One is the private key.• The second is the public key.

Page 6: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

private key

• Using the private key, I can decrypt a message that has been encrypted using my public key.

• Somebody can check that I am who I claim to be because by keeping the private key private, I am the only one who can decrypt it.

Page 7: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

authorizing keys

• If you want to give your friend access to an account, you can ask her for her public key.

• You will then authorize the public key by storing it in a file with authorized keys.

• When an somebody comes along and pretends to be your friend you can challenge her to decode a message encoded with your friends public key.

Page 8: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

public key

• Using the public key, I can encrypt a message and send it to you.

• Once the message is encrypted, I can not decode it any more. The public key can not be used to decode a message.

• This is the reason why the encryption key can be made public.

Page 9: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

communication with the server

• Assume we are using a Microsoft Windows client.

• For file editing and manipulation, we use putty.

• For file transfer, we use winscp.• Both are available on the web.

Page 10: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

password authentication

• When we login to a machine, we give a password for the user that we login as.

• This a common form of authenticiation.• The idea is that we keep the password

secret.

Page 11: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

key authenticatiton

• ssh uses public key • This a common form of authenticiation.• The idea is that we keep the password

secret.

Page 12: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

key creation

• “ssh-keygen” is the command to use to create a key. Answer all questions with the <ENTER> key.

• “cd .ssh” and “ls -l” shows you the contents of the directory .ssh created in the first step.

• The file “id_rsa.pub” has your public key.

Page 13: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

authorized_keys

• In .ssh, you can maintain a file “authorized_keys” that contains the public keys of all users you authorize to access the account, one line per user.

• “cp id_rsa.pub authorized_keys” will authorize yourself. Then “ssh user@wotan” will allow you to login again as you on wotan.

• You can also create a public key with putty.

Page 14: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

issuing commands

• While you are logged in, you talk to the computer by issuing commands.

• Your commands are read by command line interpreter.

• The command line interpreter is called a shell.

• You are using the Bourne Again Shell, bash.

Page 15: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

bash features

• bash allows to browse the command history with the up/down arrow keys.

• bash allows to edit commands with the left/right arrow keys.

• You can complete command and file names with <TAB>.

• bash comes with a language of commands that allows to write batch files.

• “exit” is the command to leave the shell.

Page 16: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

environment variables

• These are variables used by the shell. • Two important ones are

– $HOME your home directory– $PATH the location where bash will search for

executable files.

• echo $HOME will show you your home directory.

• “env” is a command that can be used to see all environment variables.

Page 17: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

bash initialization

• Files that start with a dot are hidden. They are only seen with “ls -a”.

• .bashrc is a file written in bash language that is run every time bash is started.

• .bash_profile or .profile is run when the shell is started at login.

• You can customize these files.

Page 18: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

files, directories and links

• Files are continuous chunks data on disks that are required for software applications.

• Directories are files that contain other files. Microsoft calls them folders.

• In UNIX, the directory separator is “/”• The top directory is “/” on its own.

Page 19: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

home directory

• When you first log in to wotan you are placed in your home directory /home/username

• “cd” is the command that gets you back to the home directory.

• The home directory is also abbreviated as “~“• cd ~user gets you to the home of user user.• “cd ~” does what?

Page 20: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

~/public_html

• The web server on wotan will map requests to http://wotan.liu.edu/~user to show the file ~user/public_html/index.html

• The web server will map requests to http://wotan.liu.edu/~user/file to show the file ~user/public_html/file

• The server will do this by virtue of a configuration option.

Page 21: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

changing directory, listing files

• “cd directory” changes into the directory directory

• the current directory is “.”• its parent directory is “..”• “ls” lists files

Page 22: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

users and groups

• “root” is the user name of the superuser.• The superuser has all privileges.• There are other physical users, i.e. persons

using the machine• There are users that are virtual, usually

created to run a daemon. For example, the web sever in run by a user www-data.

• Arbitrary users can be put together in groups.

Page 23: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

permission model

• Permission of files are given– to the owner of the file– to the group of the file– and to the rest of the world

• A group is a grouping of users. Unix allows to define any number of groups and make users a member of it.

• The rest of the world are all other users who have access to the system. That includes www-data!

Page 24: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

listing files

• “ls” lists files• “ls -l” make a long listing. It contains

– elementary type and permissions (see next slide)

– owner– group– size– date – name

Page 25: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

first element in ls -l• Type indicator

– d means directory– l means link– - means ordinary file

• 3 letters for permission of owner• 3 letters for permission of group• 3 letters for permission of rest of the world• r means read, w means write, x means

execute• Directories need to be executable to get in

them.

Page 26: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

change permission: chmod

• usage: chmod permission file• file is a file• permission is three numbers, first for

owner, 2nd for group and 3rd rest of the world.

• Each number is sum of – 4 for read - 2 for write– 1 for execute - 0 for no permission

• Example: chmod 764 file

Page 27: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

general structure of commands

• commandname –flag --option• Where commandname is a name of a

command• flag can be a letter• Several letters set several flags at the same

time• An option can also be expressed with - -

and a word, this is more user-friendly than flags.

Page 28: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

example command: ls

• ls lists files• ls -l makes a long listing• ls -a lists all files, not only regular files but

some hidden files as well– all files that start with a dot are hidden

• ls -la lists all files is long listing • ls --all is the same as ls -a. --all is known as

a long listing.

Page 29: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

copying and removing files

• cp file copyfile copies file file to file copyfile. If copyfile is a directory, it copies into the directory.

• mv file movedfile moves file file to file movedfile. If movedfile is a directory, it moves into the directory.

• rm file removes file, there is no recycling bin!!

Page 30: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

directories and files

• mkdir directory makes a directory• rmdir directory removes an empty directory• rm -r directory removes a directory and all

its files• more file

–Pages contents of file, no way back• less file

–Pages contents of file, “u” to go back, “q” to quit

Page 31: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

soft links

• A link is a file that contain the address of another file. Microsoft call it a shortcut.

• A soft link can be created with the command

• ln -s file link_to_file where file is a file that is already there and link_to_file is the link.

Page 32: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

file transfer• You can use winscp to upload and

download files to wotan. • If uploaded files in the web directory remain

invisible, that is most likely a problem with permission. Refer back to permissions.

• chmod 644 * will put it right for the files• chmod 755 . (yes with a dot) will put it right

for the current directory • * is a wildcard for all files.• rm -r * is a command to avoid.

Page 33: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

editing

• There are a plethora of editors available. • For the neophyte, nano works best. • nano file edits the file file.• nano -w switches off line wrapping.• nano shows the commands available at the

bottom of the screen. Note that ^letter, where letter is a letter, means pressing CONTROL and the letter letter at the same time.

Page 34: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

emacs

• This is another editor that is incredibly rich and complex.

• Written by Richard M. Stallman, of GNU and GPL fame.

• Get an emacs cheat sheet of the web before you start it. Or look at next slide.

Page 35: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

emacs commands

(here ^ stands for the control character)• ^x^s saves buffer• ^x^c exits emacs• ^g escapes out of a troublesome situation• control+space sets the mark• ^w removes until the mark (cut)• ^y pastes

Page 36: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

common emacs/bash commands

• ^k kills until the end of the line or removes empty line

• ^y yank what has been killed (paste)• ^a get to the beginning of the line• ^e get to the end of the line• These commands also work in the shell.

Page 37: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

emacs modes

• Just like people get into different moods, emacs gets into different modes.

• One mode that will split your pants is the PHP mode.

• Then look how emacs checks for completion of parenthesis, braces, brackets, and the ; and use the tab character to indent.

Page 38: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

copy and paste• Putty allows to copy and paste text

between windows and wotan.• On the windows machine, it uses the

windows approach to copy and paste• On wotan machine,

– you copy by highlighting with the mouse’ left button

– you paste using the middle button– if you don't have a middle button, use left and

right together

Page 39: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

man• man is the manual lookup command• You usually say “man command” if you

want to have an overview over the command.

• man -k keyword looks up the man pages on the computer for pages with the keyword keyword. I don't find this very effictive ;-(

Page 40: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

echo• echo is a command to desplay a line of

text.• Example: echo foo

Page 41: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

cat• This is a program that displays the contents

of a file. • Use like “cat file” to display the contents of

the file file.•

Page 42: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

more• This is a paging utility.• It is mostly used as part of a pipe.• You take the output of a command and pipe

it to the input of the next command• Example “cat longfile | more”• | is the piping operator.

Page 43: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

less• This is a paging utility. It does more than

more.• You can use the command “u” to go up.• You must use the command “q” to leave the

page.

Page 44: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

du• du is a command to look at disk usage.• du -s makes a summary, rather than listing

the usage of every. • The size is give in kilobytes. A kilobyte is

1024 bytes, not 1000 bytes.

Page 45: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

ln -s• ln -s origin target makes a link from a target

file target to an original file origin.• Then when you access target you get the

same contents as in origin.• This concept is knows as a shortcut in

Microsoft windows.

Page 46: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

ssh• ssh user@host logs you in as user user on

the host host. host can be a DNS name or an IP address.

• If you don't have you public keys in the remote account's .ssh/autorized_keys file, you will be prompted for a password.

Page 47: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

slogin• slogin is a bit of a synonym for ssh.• I use it often “slogin host -l user”.

Page 48: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

scp• This copies files from one host to another.

You can use it has complicated as “scp user1@host1:file1 user2@host2:file2.

• But often one of the users is the current user on thee current host. In that case the user@host: bit can be left out.

• If you don't have permissions via keys you will be prompted for passwords.

Page 49: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

date• date says what time it is.• This depends on the locale, as set of

conventions to deal with language issues.

Page 50: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

find• find finds file in a directory.• This is a very important and powerful

command.• Example: “find . -type f -name '*.deb'” finds

all regular files ending with “deb”• The most powerful feature is “-exec

command \;” that executes a command on the files found. Each file is represented by {}

Page 51: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

find examples• find ~/public_html -name '*.html' -exec cp {}

{}.org• find ~/public_html -name '*.css' -exec cat {}

>> /tmp/master.css

Page 52: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

output and error• In programs that ran on the shell, there are

two concepts, the output and the error.• The output is what is written by the

command in normal operation, e.g. a list of files for ls. The output is often empty, for example for the cp command.

• The error of a command is what is reported when an error occurs. Example “cp foo bar” will generate an error when there is no file foo.

Page 53: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

output redirection• The redirect the output of a command to a

file, use > or >>• Example “echo foo > /tmp/foo.file”• When you use “>” the file will be created

anew.• When you use “>>” the output will be

appended to an existing file, if any.

Page 54: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

error redirection• The redirect the output of a command to a

file, use “2>” or “2>>”• Example “cp foo 2> /tmp/error.file”• When you use “2>” the file will be created

anew.• When you use “2>>” the error will be

appended to an existing file, if any.

Page 55: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

pipes• The piping operator | connects the output of

one command to the input of another.• Example: echo “hi thomas” | mutt

[email protected]

Page 56: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

grep• grep is a very important utility to look up a

pattern in a file, as in “grep pattern file”.• Pattern is often just a string of what we

want to find.• But in the pattern, the following will have

special meaning: ( ) \ + . ? * [].• grep -r finds the pattern recursively.

Page 57: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

sort and uniq• sort sorts entries in it's inputExample: “last |

cut -f 1 | sort” gives you a sorted list of last users.

• uniq gives uniq values in an sorted list. The list has to be sorted first. Example “last | cut -f 1 | sort | uniq”

Page 58: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

crontab files• /etc/crontab is the system wide crontab.• /etc/cron.d, /etc/cron.monthly,

/etc/cron.daily, /etc/cron.weekly have more cron examples for your viewing pleasure.

• Output and error from a crontab entry is sent by local mail to the user.

• This is one reason of having mail at least set up locally, i.e. from the machine to users on the same machine.

Page 59: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

crontab entries• You can create a file that contains

commands you want to schedule regularly, and the schedule

• The file cantains lines of the form minutes hour day_of_month month day_of_week. There day_of_week ranges form 0 to 6 with 0 being Sunday.

• Save this in a file say etc/crontab.

Page 60: LIS508 using Debian GNU/Linux Thomas Krichel 2010-01-10

http://openlib.org/home/krichel

Thank you for your attention!

Please switch off machines before leaving!