360 likes | 499 Views
Information Systems Security. Linux Introduction Supplemental Notes. Command Line Interfaces. Virtual Terminals CTL-ALT-F# Consoles 1-6 are command line interfaces Console 7 is the graphical interface Each console is independent of the others Terminal Window (Konsole)
E N D
Information Systems Security Linux Introduction Supplemental Notes
Command Line Interfaces • Virtual Terminals • CTL-ALT-F# • Consoles 1-6 are command line interfaces • Console 7 is the graphical interface • Each console is independent of the others • Terminal Window (Konsole) • Accessed as a shell window in the graphical interface. • Provides an emulation of a virtual console.
Linux Help Resources • man pages • online reference manuals • example: man man • Uses less pager for navigation (man less) • info pages • more sophisticated navigation than man pages (info info) • Release notes • /usr/share/doc/release-notes • Howto files (Linux Documentation Project) • /usr/share/doc/howto/en/htmlortxt • Package help files • /usr/share/doc/packages/package-name
YaST Management Utility • Yet another Setup Utility • Works with command line or graphical environment • Allows management of • Software packages • User & Group Accounts • Printer Configuration • View Hardware Configuration • X Windows configuration
Linux Filesystem Structure • Hierarchical • Tree-structured directories • Paths • Absolute Paths • always start from / • /home/username/.bashrc • ~/.bashrc • Relative Paths • always start from current directory • ../../tmp/test.txt • ./bin/test.sh • .bashrc
Linux File System Wild Cards • Wild cards can be used to represent one or more characters in a path or filename. • ? can be used to represent 1 character • * can be used to represent a string of 0 or more characters. • Examples: • ls test?.txt • lists files like test0.txt, test1.txt, testA.txt, etc. • ls test*.txt • lists files like test.txt, test0.txt, test01.txt, testA.txt, test3X.Y.txt, etc.
Search File Content using grep • Syntax: grep pattern filename(s) • Searches the specified file(s) for the given pattern. • Patterns may be specified as: • simple patterns (text) • regular expressions (symbolic patterns) • extended regular expressions (symbolic patterns (use egrep instead of grep) • Use quotation marks to prevent the shell from interpreting special characters such as ? or * • See man 7 regex for more information about regular expressions. • grep examples... • grep "root" /etc/*
Commands for Archiving and Compressing Files • Archiving combines multiple files into a single file. • Compressing (zipping) a file reduces its size by removing unneeded characters. • In Linux/UNIX, archiving and compressing a file are two separate steps.
Command Shells • The command shell program provides the command line interface in a nongraphical environment. • Accepts commands entered by the user on the command line. • Runs the specified command and displays the result on the screen. • Also called the command interpreter. • Linux supports a variety of shells: • bash - the Bourne Again SHell, default Linux shell • sh - the Bourne SH, the original UNIX shell • csh - the c shell • ksh - the Korn shell • zsh - the z shell
Using the Command Line • Start a shell window (Konsole) • Using commands --- previous examples... • Pipes and redirection • cat /etc/passwd | less (pipe) • cat /etc/passwd > mypasswd.txt (redirect) • cat /etc/group >> mypasswd.txt (append)
File Ownerships and Permissions • All files have a user owner, a group owner, and a set of permissions. • Three permission types: (r)ead, (w)rite, and e(x)ecute • Three access classes: (u)ser owner, (g)roup owner, and (o)ther • To view ownerships and permissions: ls -l • Modifying permissions: chmod
Directory Ownerships and Permissions • Directories are also files, and have a user owner, a group owner, and a set of permissions. • Read permissions allow a user to list the contents of a directory. • Write permissions allow a user to add or remove files in the directory. • Execute permissions allow a user to access a file within the directory. • Directory permissions are modified with the chmod command.
File and Directory Permissions • Permissions control access to and use of files and directories in UNIX/Linux. • Use ls -l to view permissions for files. • Use chmod to change the permissions for files. • Syntax: • Symbolic: chmod [ugoa][+-=]rwx file(s) • Octal: chmod nnn files(s)
chmod Symbolic Notation • chmod [ugoa] [+ - =] [rwx]file(s) • ugoa --- to whom does the change apply? • u = user (owner), • g = group, • o = others, • a = all • + - = --- is the change relative or absolute? • + => add the specified permission • - => remove the specified permission • = => set exactly the specified permissions • rwx --- what permissions are being applied? • r = permission to read the file or directory • w = permission to write to the file or directory • x = permission to execute (run) the file or access the directory.
chmod examples [elvis@station elvis]$ ls -l foo -rw-rw-r-- 1 elvis elvis 42 Jan 16 08:09 foo What is the effect of the following commands? • chmod o-r foo • chmod g-w foo • chmod ug+x foo • chmod o+w foo • chmod go-rwx foo • chmod a-w foo • chmod uo-r foo • chmod go=rx foo
chmod Octal Notation • We've seen symbolic notation with chmod: $ chmod og-r diary Symbolic notation allows you to add or subtract permissions relative to the current permissions. • We can also use octal notation with chmod:$ chmod 600 diaryOctal notation allows you to easily set all permissions with one command.
Interpreting Octal Notation • In octal notation, each permission has a specific value: r = 4 w = 2 x = 1 • The octal permission value for u, g, o is the sum of the specific permission values:7 = 4 + 2 + 1 = rwx(all) permissions6 = 4 + 2 = rw-permissions5 = 4 + 1 = r-x permissions4 = 4 = r-- permissions3 = 2 + 1 = -wx permissions2 = 2 = -w- permissions1 = 1 = --x permissions0 = 0 = --- permisssions
Octal Notation Examples • What is the meaning of the permission values in the following examples? $ chmod 755 ./project $ chmod 644 .plan $ chmod 600 schedule $ chmod 777 ./bin $ chmod 750 ./cent297c
Text Editors • Needed for editing Linux configuration files, which are usually ASCII text files. • Graphical text editors • gedit, kedit, kate, etc.... • Work fine as long as there is a GUI... • Terminal based text editors • vi, emacs, pico • MUST be used in a command-line environment such as a virtual console as there is no support for graphical text editors.
Overview of Terminal Based Text Editors • vi or vim • Most commonly used by system administrators • Moderately complex and powerful tool. • Installed by default on ALL UNIX/Linux systems --- so it's always available • emacs • Frequently used by programmers. • Very complex to learn and use and very powerful. • NOT installed by default and is not always available. • pico • Simple, menu-driven text editor • Easy to learn and use. • Not very powerful. • May not always be installed, but usually is.
vim intro • vi • visual editor • commonly used Unix text editor • vim • vi improved • updated version of vi that’s somewhat easier to use • default version of vi provided with Linux
vim basics • vim filename • creates and new file and opens it for editing • vi modes • command mode --- used for entering commands, saving files, and quitting vi • insert mode --- used for entering text • The following file includes a summary of vi commands 01_vi.pdf
Shell Scripts • A shell script in Unix is essentially the same thing as a batch file in DOS • A file that contains a sequence of commands that the Unix operating system can interpret and run • To create a Unix script • Create the script file using vi or vim • Save the file • Set the permissions of the file to make it executable
Example of a shell script prompt% vim myscript.sh i (change to insert mode) #! /bin/bash # display the default shell echo $SHELL # display the terminal type echo $TERM ESC (exit insert mode/return to command mode) :wq (save file and exit)
Setting permissions prompt% ls -l myscript (displays permissions) prompt% chmod u+x myscript uses chmod to make the file myscript executable by adding execute (x) permission to the user (u) permissions.
Running the script prompt% ./myscript Note: the filename myscript is preceded by the symbols ./ to indicate that the file is located in the current directory. In Unix/Linux, the current directory is frequently not in the default search path, so entering myscript without ./ would result in an error message that the command was not found.
Sending output to a file prompt% ./myscript > myscript.out As in DOS, the symbol > can be used to redirect the output of a command to a file. The symbols >> can be used to append the output of a command to an existing (or new) file.
If . (or any other path) is not in your path: • For bash shell: • Edit the .bashrc file: vi ~/.bashrc • Add the line: export PATH=$PATH:/addedpath • set (instead of export) works too • Source the file: source ~/.bashrc • For csh or tcsh: • Edit .cshrc file or .tcshrc • Add line: set PATH = ($PATH addedpath) • Source the file
How will you know if it’s not in your path? • You won’t be able to run the command • Use “which” command to find out where the command is • which ifconfig • If it is not found, you got to find it and add it’s path to your PATH variable • Run: $PATH to find out what your path is
Networking commands and files • http://www.reallylinux.com/docs/admin.shtmlBasic commands for sys admins (everything, not only networking) • http://www.yolinux.com/TUTORIALS/LinuxTutorialNetworking.html#CONFIGFILES • http://www.yolinux.com/TUTORIALS/LinuxTutorialNetworking.htmlComprehensive sys admin tutorial