Tải bản đầy đủ (.pdf) (50 trang)

Sun Fundamentals of Solaris 7 EU-118 Student Guide With Instructor Notes phần 7 doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (247.5 KB, 50 trang )

8
8-26 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Default Permissions
Changing the umask Value
The umask value can be changed at the command line or with a umask
command in the user’s startup (.profile) file.
Changing umask for the Current Shell and its Subshells
You would:
1. Verify the current umask.
$ umask
022
2. Change the umask value to 027 and verify.
$ umask 027
$ umask
027
The new umask value will be lost when you log out of the system
unless the umask command is placed in the .profile file. This file is
discussed in detail in Module 11, ‘‘Initialization Files.”

Caution – If terminal window is opened from the Front Panel,
umask
may display
incorrectly due to a known bug. This problem can be circumvented by opening a terminal
window from the Workspace Manager instead.
8
File Security 8-27
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Exercise: Changing File Permissions
Exercise objective – The purpose of this lab is to give you practice
reading permissions on files and changing permissions using symbolic


or octal notation.
Tasks
Complete or answer the following:
1. Execute the following commands:
$ mkdir ~/perm
$ cd /etc
$ cp group passwd motd vfstab dumpdates shadow ~/perm
$ cd
$ cp -r /etc/skel perm
When trying to copy /etc/shadow an error message was
displayed. Why?
___________________________________________________________
___________________________________________________________
2. Change directory to perm and complete the following table:
3. Create a new file and a new directory.
▼ What are the default permissions given to the new file?
_______________________________________________________
▼ What are the default permissions given to the new directory?
_______________________________________________________
File or
Directory
User
Permissions
Group
Permissions
Other
Permissions
Octal Value
group rw-
passwd r

vfstab rw-
skel 755
8
8-28 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Exercise: Changing File Permissions
Tasks
4. In a directory with permissions of drwxr-xr , who can perform
the following actions with the files shown below? Put an X next to
each allowed action.
-rw-r r
user: read___ modify____ delete___ execute___
group: read___ modify___ delete___ execute___
others: read___ modify___ delete___ execute___
-rwxrwxr-x
user: read___ modify____ delete___ execute___
group: read___ modify___ delete___ execute___
others: read___ modify___ delete___ execute___
5. Using symbolic mode, add write permission for group to the motd
file.
___________________________________________________________
6. Using symbolic mode, remove group read on the file dumpdates.
___________________________________________________________
7. Using octal mode, change the permissions on the file motd to
rwxrw
___________________________________________________________
8. Using octal mode, change the permissions on the file group to add
write permission for others.
___________________________________________________________
9. Why is execute not a default permission for a newly created file?

___________________________________________________________
___________________________________________________________
10. Create a new file called memo in your practice directory.
___________________________________________________________
8
File Security 8-29
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Exercise: Changing File Permissions
Tasks
11. Remove the read permission for the owner from the file memo in
the practice directory. Use either symbolic or octal mode.
___________________________________________________________
What happens when you try to use the cat command to view the
memo file?
___________________________________________________________
What happens when you try to copy the memo file?
___________________________________________________________
___________________________________________________________
Workshop Labs
Use what you have learned so far in this course to work through the
following:
1. Make a directory containing some of your files available to
coworkers in your group but not to others.
2. Create a directory under your home directory called Textfiles.
3. Put a copy of four of the text files from your home directory into
the new directory.
4. Change permissions appropriately so that other users in your
group can copy files from the Textfiles directory.
5. Create a file in the directory which lists the names of all of the four
text files in the directory. Make the file modifiable by someone in

your group.
8
8-30 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Exercise: Changing File Permissions
Exercise Summary
Discussion – Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the “About This Course” module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.
● Experiences

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.
● Interpretations

Ask students to interpret what they observed during any aspects of this exercise.
● Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.
● Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.
8
File Security 8-31

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Exercise: Changing File Permissions
Exercise Solutions
Complete the following steps:
1. Execute the following commands:
$ mkdir ~/perm
$ cd /etc
$ cp group passwd motd vfstab dumpdates shadow ~/perm
$ cd
$ cp -r /etc/skel perm
When trying to copy /etc/shadow an error message was
displayed. Why? Because, as a user who is not part of the sys group,
you have no permissions on this file.
2. Change directory to perm and complete the following table:
$ cd perm
$ ls -l
3. Create a new file and a new directory.
▼ What are the default permissions given to the new file?
rw-r r
▼ What are the default permissions given to the new directory?
rwxr-xr-x
File or
Directory
User
Permissions
Group
Permissions
Other
Permissions
Octal Value

group rw- r r 644
passwd rw- r r 644
vfstab rw- r r 644
skel rwx r-x r-x 755
8
8-32 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Exercise: Changing File Permissions
Exercise Solutions
4. In a directory with permissions of drwxr-xr , who can perform
the following actions with the files shown below? Put an X next to
each allowed action.
-rw-r r
user: read X modify X delete X execute___
group:read X modify___ delete___ execute___
others: read___ modify___ delete___ execute___
-rwxrwxr-x
user: read X modify X delete X execute X
group: read X modify X delete___ execute X
others: read___ modify___ delete___ execute___
5. Using symbolic mode, add write permission for group to the motd
file.
$ chmod g+w motd
6. Using symbolic mode, remove group read on the file dumpdates.
$ chmod g-r dumpdates
7. Using octal mode, change the permissions on the file motd to
rwxrw
$ chmod 760 motd
8. Using octal mode, change the permissions on the file group to add
write permission for others.

$ chmod 646 group
9. Why is execute not a default permission for a newly created file?
Most files are not binary or executable scripts. Having execute as a
default permission for a file would cause the system to see all new files as
executables.
8
File Security 8-33
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Exercise: Changing File Permissions
Exercise Solutions (Continued)
10. Create a new file called memo in your practice directory.
$ touch ~/practice/memo
11. Remove the read permission for the owner from the file memo in
the practice directory. Use either symbolic or octal mode.
$ chmod u-r ~/practice/memo or
chmod 244 ~/practice/memo
What happens when you try to use the cat command to view the
memo file?
You cannot use the cat command because the read permission has been
removed for the user. (Even though you are part of the group, the
permissions are looked at in the order they appear.)
What happens when you try to copy the memo file?
You cannot copy the file because, as in step 4, the user has no read
permission.
8
8-34 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

❑ Display file permissions
❑ Define permission types (read, write, and execute)
❑ Set and change file permissions using symbolic and octal notation
❑ Display the umask value of a file or directory
8
File Security 8-35
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Think Beyond
In your work environment, is file security an important issue? What
advantages or disadvantages are there to working in a secure
computing environment?
8
8-36 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
9-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
UsingtheviEditor
9
Objectives
Upon completion of this module, you should be able to:
● Differentiate between the three modes of vi and identify the
commands that belong to each mode
● Start vi
● Position and move the cursor in vi
● Create text in vi
● Delete text in vi
● Copy or move text in vi
● Set vi options
● Exit the vi editor
● Perform search and replace functions within vi

9
9-2 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.
Discussion – Editing system files is a powerful tool for customizing
the Solaris environment. What tools would you use to edit system
files?
Additional Resources
Additional resources – The following reference can provide additional
details on the topics discussed in this module:
● Solaris User’s Guide, Part Number 802-6499
9
Using the
vi
Editor 9-3
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Introduction to vi
The visual display (vi) editor is an interactive editor that is used to
create and/or modify text files.
The vi editor uses a screen display, but you cannot use the mouse to
position the cursor.
All editing with the vi editor is done within a buffer. Changes can be
written to the disk or discarded.
It is important for users who are learning to become system
administrators to know how to use vi. It is the only full screen editor

that can be used to edit crucial system files. This skill is also needed in
case the windowing system is not available.

Depending on the instructor’s style, this module may be best taught by covering the basic
modes and commands of
vi
contained in the lecture parts of this module in a summary
fashion. The purpose of the lab for this module is to allow the students to learn
vi
by
using it. The lab covers in a practical fashion much of what is covered in the module,
along with some things that are not.
9
9-4 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
vi Modes
There are three modes of operation in vi:
● Command mode
● Entry mode
● Last-line mode
When you open a file with vi, you are in command mode. In this mode,
you can enter positioning and editing commands to perform functions.
While in command mode you can do advanced editing commands by
typing a colon (:), which places you at the bottom line of the screen.
This is called last-line mode. However, all commands are initiated from
command mode.
9
Using the
vi
Editor 9-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
vi Modes
You must be in entry mode to enter text. To enter text, you must type a
vi insert command such as i, o,or a. This takes vi out of command
mode and puts it into entry mode. In this mode, text will not be
interpreted as editing commands. When you finish entering text in
your file, press the Escape key to return to command mode.
Figure 9-1 vi Modes
: / ? i a o
Escape
Command
mode
Return
Last-line
mode
Entry
mode
9
9-6 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Invoking vi
Command Format
vi [
option(s)
][
filename
]
view [
filename
]

Example
To create a new file, invoke vi with a new file name by typing
$ vi
filename
Table 9-1 contains commands you can use to create, edit, or view a file.
Note – Running vi with set showmode displays which mode you are
in on the screen (command, insert or append mode). Caution should
be taken when using this on older dumb terminals, as some do not
consistently display the mode, even with showmode turned on.

Consider having students run
vi
with
set showmode
set from the beginning.
Table 9-1 vi Commands
Command Meaning
vi
filename
Open or create a file
vi Open a new file to be named later
vi -r
filename
Recover a crashed file
view
filename
Open a file as read-only
vedit
filename
Runs vi with set showmode automatically set. (See

Note.)
9
Using the
vi
Editor 9-7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Input Commands
To append or insert text, use the following options:
Table 9-2 Append and Insert Commands
Command Meaning
a Append text after the cursor
A Append text at the end of the line
i Insert text before the cursor
I Insert text at the beginning of the
line
o Open a new line below the cursor
O Open a new line above the cursor
9
9-8 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Positioning Commands
The following pages list the vi editor’s editing and positioning
commands, which are used to make changes.
The vi editor is case sensitive, so use the specified case when using the
editing and positioning commands.
The Table 9-3 shows the key sequences for character movement:.
Table 9-3 Key Sequences
Command Meaning
h, ←, or Back Space Move left one character
j or ↓ Move down one line

k or ↑ Move up one line
l,→, or Space bar Move right (forward) one character
w Move forward one word (including punctuation)
W Move forward one word (past punctuation)
b Move back one word (including punctuation)
B Move back one word (past punctuation)
e Move to end of current word
$ Move to end of line
0 (zero) or ^ Move to beginning of line
Return Move down to beginning of next line
H Move to top of screen
M Move to middle of screen
L Move to bottom of screen
Control-f Page forward one screen
Control-d Scroll down one-half screen
Control-b Page back one screen
Control-u Scroll up one-half screen
9
Using the
vi
Editor 9-9
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Editing Commands
Deleting Text
To delete text, use the following options:
Table 9-4 Text Deletion Commands
Command Meaning
x (lowercase) Delete character at the cursor
X (uppercase) Delete character to the left of the cursor
dw Delete word (or part of word to right of cursor)

3dw Delete three words
dd Delete line containing the cursor
3dd Delete three lines
D Delete line to right of cursor (from cursor position to
the end of the line)
dG Delete to end of file
d1G Delete from beginning of file to cursor
:5,10d Delete lines 5 through 10
9
9-10 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Editing Commands
Undoing, Repeating, and Changing Text Commands
To change text or to cancel or repeat edit functions, use the following
commands. Many of these commands change you to Insert mode until
you press Escape.
Table 9-5 Editing Commands
Command Meaning
cw Change word (or part of word) at the cursor
location to the end of the word
3cw Change three words
R Overwrite or replace characters on line
C Change from cursor to end of line
s Substitute string for character(s)
r Replace character at cursor with one other character
i (Return) Break line
J Join current line and line below
xp Transpose character at cursor and character to the
right
~ Change case of letter (upper or lower) at cursor

u Undo previous command
U Undo all changes to current line
:u Undo previous last-line command
9
Using the
vi
Editor 9-11
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Editing Commands
Copying and Pasting Text
To copy and paste text, use the following options:
Note – Both delete and yank write to a buffer. When yanking, deleting,
and pasting, the put commands insert the text differently depending
on whether you are pasting a word(s) or a line(s).
Table 9-6 Copy and Paste Commands
Command Meaning
yy Yank a copy of line
Y Yank a copy of line
p Put yanked or deleted line below current line
P Put yanked or deleted line above current line
:1,3 co 5 Copy lines 1 through 3 and put after line 5
:4,6 m 8 Move lines 4 through 6 to line 8 (line 6 becomes line
8; line 5 becomes line 7, and line 4 becomes line 6)
9
9-12 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Editing Commands
Saving and Quitting Files
To save and quit a file, use the following options:
Table 9-7 Save and Quit Commands

Command Meaning
:w Save changes (write buffer)
:w
new_filename
Write buffer to
new_filename
:wq Save changes and quit vi
ZZ Save changes and quit vi
:q! Quit without saving changes
:wq! Save changes and quit vi (The ! will override read
only permissions if you are the owner of the file.)
9
Using the
vi
Editor 9-13
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Advanced Editing Options
The vi editor includes options for customizing your edit sessions,
such as:
● Displaying line numbers
● Displaying invisible characters such as tab and end-of-line
characters
The set command is used from last-line mode to control these options.
These options can also be placed in a file the user creates in their home
directory called .exrc. The set options are placed in this file, without
the preceding colon, one command to a line. Once the .exrc file exists,
it is read by the system each time a vi session is opened.
Table 9-8 Edit Session Customization Commands
Command Meaning
:set nu Show line numbers

:set nonu Hide line numbers
:set ic Instruct searches to ignore case
:set noic Instruct searches to be case sensitive
:set list Display invisible characters such as tab and
end-of-line
:set nolist Turn off the display of invisible characters
:set showmode Display current mode of operation
:set noshowmode Turn off mode display
:set Display all vi variables set
:set all Display all possible vi variables and their current
settings
9
9-14 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Advanced Editing Options
To find a line or to search and replace and do advanced editing, use
the following options:
To clear the screen or insert files, use the following options:
To search and replace text, use the following options:
Table 9-9 Advanced Editing/Search Commands
Command Meaning
G Go to last line of file
1G Go to first line of file
:21 Go to line 21
21G Go to line 21
Table 9-10 Clearing/Insertion Commands
Command Meaning
Control-L Clear (refresh) scrambled screen
:r
filename

Insert (read) file at line after cursor
:34 r
filename
Insert file after line 34
Table 9-11 Search and Replace Commands
Command Meaning
/
string
Search forward for
string
?
string
Search backward for
string
n Find next occurrence of string
N Find previous occurrence of string
:%s/
old
/
new
/g Search and replace globally

×