File Permissions and ownership

advertisement
File Permissions and ownership
Changing ownership:
chown UserName FileName
chgrp GroupName FileName
Changing permissions:
chmod value filespec
e.g. chmod 777 foo
r
4
chmod
chmod
chmod
chmod
chmod
chmod
chmod
chmod
chmod
w
2
x
1
777 filespec
755 filespec
644 filespec
u+rx filespec
u=rx filespec
ugo+rx filespec
a-rx filespec
+x filespec =
+rw filespec =
rwxrwxrwx
rxwr-xr-x
rw-r—r—
Adds rx for the “user”
Absolutely sets permission to rx for “user”
Adds rx for all users
Removes rx for all users
chmod ugo+x filespec
chmod ugo+rw filespec # subject to umask
chmod -R 777 filespec recursively changes
chown -R user filespec recursively changes
Default file creation modes;
umask
umask
umask
umask
000
022
002
066
rw-rw-rw
rw-r--rrw-rw-r-rw--—---
----------------------------------------------------------------------Assume: you do Not own a file, and its parent directory is drwxrwxrwx
If the file is Write protected
rw-r--r--
1 root
sys
12 Oct 30 20:19 foo
It Cannot be:
Changed:
e.g.
(see exception for vi editor below)
cp a foo
cat a >>foo
echo hello >>foo
chmod +w foo
chown userme foo
It Can be:
removed , renamed or copied to another file
rm foo
cp foo newfoo
mv foo newfoo
Caveat: Editors in Linux version of Unix:
In the above case, the file foo could be changed using an editor
such as "vi", even though it is write protected.
Note that when saved (:wq!), the ownership will be changed as
well. It does now work this way in commercial versions of Unix
such as hpux and OSF1. To prevent this, set directory permissions to
to write protect. e.g. drwx-rx-rxDirectories:
Remember, directories are just another type of file on the Unix
system. Their contents, is a listing of files within the directory
along with information about those files. When you change the
contents of a directory, you are, in effect, changing the contents
of the special directory file itself.
Operations such as "cp", "rm", and "mv" would require updating the
directory's listing, therefore, these operations are subject to the
protections set on the parent directory of any file.
Assume a directory is write protected, and you are not the owner
drwxr-xr-x
rw-r--r-rw-rw-rw-
1 mike
1 mike
1 mike
user
user
user
12 Oct 30 20:19 /home/mike
12 Oct 30 20:19 foo
12 Oct 30 20:19 nuke
The following operations would Not be allowed.
rm foo
mv foo newfoo
cp foo newfoo
mv foo nuke
cat a >>foo
echo hello >>foo
cp nuke foo
The following Would be allowed
echo hello >nuke
cat foo >>nuke
cp foo nuke
Note:
The vi editor behaves as it should with regards to permissions,
when the parent directory is write protected.
If a directory is not executable, only the owner and root can have their way
with the files therein. This includes all sub-directories.
drwxr--r-rw-r--r-rw-rw-rw-
1 mike
1 mike
1 mike
Other users could not:
cd /home/mike
ls -l /home/mike
vi /home/mike/nuke
user
user
user
12 Oct 30 20:19 /home/mike
12 Oct 30 20:19 foo
12 Oct 30 20:19 nuke
Download