首页 > 科技 > Linux Shell : privilege and attribute

Linux Shell : privilege and attribute

2005年11月22日 21点58分 发表评论 阅读评论

There are total three mode to access file system:

-Read: is able to display the file’s content.
-Write: is able to be modified or deleted.
-Execute: if the file is shell script or executable,it’s able to be executed.

When a file is created, Linux keeps all its information including:

Location, File types, File length, Owners, Owner’s default group,Users who can access this file,
Last updated time, Privilege.

For example:

# ls -l
total 4132
-rwxr-xr-x    1    root    root    3756    Oct 14 04:44    dmesg

total: the directory’s capacity
-rwxr-xr-x : privilege
1 : the number of hard link
root: the owner
root: the owner’s default group
3576: the file length.(byte)
Oct 14 04:44 : last updated time
dmesg : file name

The file cuold have one of the following file types:
d : directory
l : link
s : socket file
b : block device
c : character device
p : pipe
– : general file

We could use ‘chmod’ command in the following two modes:

1.standard: # chmod ugo +/- rwx file
2.absolute mode: # chmod [mode] file eg: chmod 775 1
The standard mode is better than absolute mode for its clear operation.
Note,if we use multiple operator in the chmod command, a comma must be added.
for example: # chmod g+r,o-w filename

The directory privilege is prior than file lever,it has the main two accessing:

-Reading: list the directory’s content
-Write: is about create new file or folder.

suid/guid

Many operating systems disallow these parameter for security reason.Suid: if this key word is set in the privilege, it means that when other user even who are not root or belong to root group could execute the file as root. Of course,it could cause
many security problems what we must care.

How to find if the Linux distribute supports suid and guid:

# cd /bin
# ls -l | grep '^...s'

eg, in RHEL 3.0 update4, the following command files will be listed:
mount, umount, ping, ping6, su, traceroute, traceroute6.
if we use absolute mode to set suid,just take the position to number ‘4’;
if guid were used, the number is ‘2’;
if suid and guid were set together,the right number is ‘6’ which means 4+2.

A useful linux command to list all the users:

# cat /etc/passwd

To find the group which user are belong to:

# groups

To identify user’s id:

# id

umask command indicates the default mode when create a new file or directory.we could configure umask parameter at /etc/profile. Every user has his own umask which could be unique.The users can set the unique umask number, and take it active in the $HOME/.profile or $HOME/.bask_profile.To file,the maximum umask number is 6;To directory, the maximum umask numner is 7.

How to identify the setting umask number? Issue the command:

# umask

Q: The default umask number is 022.In the /root, I created file named ‘myfile’ by the following
command:

# touch myfile
# ls -l myfile
-rw-r--r--

Why?
A:000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7

Because ‘myfile’ is just file, not directory,so its maximum umask is 666. We could know the default
umask number is 022 from the question, 2 means ‘-w-‘,6 means ‘rw-‘,then the result should be ‘r–‘.
So,the privilege of ‘myfile’ is ‘-rw-r–r–‘.

Soft link:

# link -s source-path target-path
分类: 科技 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
您必须在 登录 后才能发布评论.