• No results found

22 fdisk and mkfs

26.5  Ext2 attributes

The chattr command manipulates ext2 filesystem attributes.   lsattr displays these attributes.  The following attributes can be set on the ext2 filesystem (and not on other filesystems): • i – immutable – the file cannot be changed, unless the immutable bit is removed first • a – append only – this file can only be appended to, not rewritten. • s – secure deletion – after the file is deleted, the blocks that stored its data are blanked out. Here's an example of setting the immutable flag on a file. [jack@foo attr]$ ls -l

-rw-rw-r-- 1 jack jack 0 Apr 30 14:25 dfjqw -rw-rw-r-- 1 jack jack 0 Apr 30 14:25 qwoo1 -rw-rw-r-- 1 jack jack 0 Apr 30 14:25 woow [jack@foo attr]$ lsattr

--- ./dfjqw --- ./qwoo1 --- ./woow

[jack@foo attr]$ chattr +i dfjqw

26 Permissions LPI 101 Course Notes 181

[jack@foo attr]$ su

Password:

[root@foo attr]# chattr +i dfjqw

[root@foo attr]# rm dfjqw

rm: remove write-protected regular empty file `dfjqw'? y

rm: cannot remove `dfjqw': Operation not permitted [root@foo attr]# lsattr

---i--- ./dfjqw --- ./qwoo1 --- ./woow

[root@tonto attr]# ls >> dfjqw bash: dfjqw: Permission denied

26.6 Review

Quiz questions

1. What is the effect of setting the sticky bit for a file? 2. What is the meaning of chmod 640 filename?

3. Which users may change the permissions on a given file?

4. What are the default permissions for a file and for a directory when the umask is 0027? 5. What is the effect of the set group­id bit for a directory?

6. Which filesystems support chattr and lsattr? Assignment

1. Write down the commands do do the following.   Create files using  touch  and set the  following permissions:

file1 ­rw­rw­rw­; file2 ­rwxrwxrwx; file3 ­rwsr­xr­x; file4 ­rwx­­­­­­; file5 ­­­­­­­­­x;  file6 ­r­xr­Sr­x; file7 ­rws­­­­­­ (that's an entirely useless set­uid bit that is).

Create directories using mkdir and set the following permissions:

dir1 drwxrwxrwx; dir2 drwx­­x­­x; dir3 drwxrwsr­x; dir4 drwxrwxrwt; dir5 ­­­­­­­­­­;  dir6 drwxr­xr­x; file7 drwxr­x­­­

2. Run the command chmod ­R 000 ~.  What happens, and why?  How can you fix it?  Hint:  find ­type d | xargs chmod something {} \; ... repeat ...

3. Use find to create a list of the files on your disk which are world writable. 4. Sort this list into different types of files.  Hint: use ls ­ld to show the file type ... Answers to quiz questions 1. Nothing happens, except that the sticky bit is set. 2. Set permissions to rw­r­­­­­ for the file. 3. Root and the file owner.  Not group members. 4. For a file 0666 ­ 027 = 0640 (rw­r­­­­­), for a directory 0777 ­ 027 = 0750 (rwxr­x­­­). 5. Files and directories in the directory receive the group of the directory.

182 LPI 101 Course Notes 26 Permissions

27 File ownership LPI 101 Course Notes 183

27 File ownership

I really hate this damned machine I wish that they would sell it. It never does quite what I want But only what I tell it.  (All the good quotes were taken) In Linux, you get your own files.   Nobody else can fiddle them, unless you allow them to.  This chapter is about setting the ownership of files.

LPIC topic 1.104.6 — Manage file ownership [1]

Weight: 1 Objective Candidates should be able to control user and group ownership of files. This objective  includes the ability to change the user and group owner of a file as well as the default group  owner for new files. Key files, terms, and utilities include chmod Change file mode (permissions) chown Change file owner (and maybe group too) chgrp Change file group

27.1 File ownership

Every file on the Linux filesystem is assigned a single owner and a single group – yes, only  one group.   Linux allows you to assign permissions for the owner (user), group, and other  users, namely permission to read, write and execute (or search, for directories). The user that creates a file is the owner of the file, and the assigned group is the primary group  of the user (by default).  If the permissions on the file permit reading, writing or executing by  the group, any member of the group can exercise those permissions. The owner of a file can change its group to any other group of which he is a member.  The  command for this function is chgrp.  Root can change the group of any file to any value. The user root is able to change ownership of files using chown.

One day jack deletes his .bashrc.  Oops.  [jack@foo jack]$ rm .bashrc

So root made another one for him (because jack didn't know how to do it himself, I  suspect).

[jack@foo jack]$ su

Password:

[root@tonto jack]# cp /etc/skel/.bashrc .

[root@tonto jack]# ls -l .bashrc

184 LPI 101 Course Notes 27 File ownership

Unfortunately, the ownership was incorrect – but that was fixed with chown.  In fact, 

chown can set the group as well.

[root@tonto jack]# chown jack.users .bashrc

[root@tonto jack]# exit

If jack doesn't like the file's group being “users”, he can change it. [jack@foo jack]# ls -la .bash*

-rw--- 1 jack jack 10655 Apr 30 15:38 .bash_history

-rw--- 1 jack jack 24 Apr 8 11:45 .bash_logout -rw--- 1 jack jack 213 Apr 29 14:58

.bash_profile

-rw-r--r-- 1 jack users 124 May 1 14:03 .bashrc [jack@foo jack]$ chgrp jack .bashrc

A user can only change the group to another group of which he is a member.  Here  jack discovers he is not a user.

[jack@foo jack]$ chgrp users .bashrc

chgrp: changing group of `.bashrc': Operation not permitted [jack@foo jack]$ id

uid=513(jack) gid=514(jack) groups=514(jack),101(boneheads) [jack@foo jack]$ chgrp boneheads .bashrc

[jack@foo jack]$ ls -la .bashrc

-rw-r--r-- 1 jack boneheads 124 May 1 14:03 .bashrc

Related documents