Both file attributes and permissions determine user and group access to files throughout the file system. Therefore, being able to use file attributes and permissions effectively is an essential system administrator skill. In this Hands-On lab, you will be using commands to view and set permissions and attributes for files. When the lab is complete, you should know how to use file attributes and permissions to control user and group access to files in the file system.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- View the Current Permissions of /opt/myapp/start.sh
Let’s see where we stand, as far as permissions go. Run
ls -l
andstat
on the/opt/myapp/start.sh
file:cd /opt/myapp ls -l start.sh stat start.sh
- Change Permissions on /opt/myapp/start.sh to Allow Full Privileges for User and Group Only
Currently, the permissions of the file
/opt/myapp/start.sh
arerw-r--r--
, or mode644
. We need the user and group to have all permissions and the others to have none. Using either command will have the same result:ls -l start.sh chmod u=rwx,g+wx,o-r start.sh ls -l start.sh stat start.sh chmod 770 start.sh stat start.sh
- Verify That /opt/myapp/start.sh Is Executable
The permissions of the file
/opt/myapp/start.sh
should now be-rwxrwx---
or mode770
, and the file should execute. Look at the permissions again to make sure:stat start.sh
Now let’s try running it:
./start.sh
- Make the /opt/myapp/start.sh Immutable Using a File Attribute
The
i
attribute should appear when we runlsattr
on the file:lsattr start.sh
If it doesn’t, then we’ve got to set it:
sudo chattr +i start.sh
Verify that the file is set immutable:
lsattr start.sh
Note the use of
sudo
there. We’ve got to runchattr
asroot
.