Knowing how to work with files in Linux is an integral part of being a sysadmin. We need to be able to find them, give and revoke permissions on them, and assign or reassign ownership. This hands-on lab is going to give us some practice doing all of those things.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Find Custom Application Files under /opt/myapp and Display a Detailed Listing of Them
We’re going to need elevated privileges for this lab, so once we’re logged in let’s just become
root
right off withsudo -i
.Use the
find
command to provide a detailed listing of the/opt/
directory:find /opt
Our
myapp
directory is sitting in there, now let’s see what happening in there as far as files go, like who owns them:find /opt/myapp -ls
The
root
user owns everything. That’s not good. We’ve got to change that.- Change the /opt/myapp Directory to be Owned by the cloud_user and the Group devop
Use the
chown
command to change user ownership to thecloud_user
and the groupdevop
for the/opt/myapp
directory and its contents:find /opt/myapp -exec sudo chown cloud_user:devop {} ;
To test, run
find /opt/myapp -ls
again, and see if ourchown
command actually changed ownership on these files.It worked. Now we’ve got some permissions problems though.
- Set Permissions for /opt/myapp Files
Use the
chmod
command to setrw-rw----
, or660
, permissions on all/opt/myapp
files, except for the directory itself and the/opt/myapp/start.sh
script:find /opt/myapp -name "d*" -ok chmod 660 {} ;
Just type y for each yes/no prompt.
Next, change permissions on anything that does not start with d (the directory itself and the
start.sh
script):find /opt/myapp '!' -name "d*" -ok chmod 770 {} ;
Again, type y for each yes/no prompt.
- Find a Directory under /home Which Is Not Owned by a User or Group
Use the
find
command to find any directories in/home
files which lack a user and group owner:find /home -nouser -nogroup -ls
- Execute the chown Command with the find Command
Find files and directories that were owned by
devuser
:find /home -ls
Check for anything that doesn’t have user or group ownership:
find /home -nouser -a -nogroup -ls
Run
chown
withfind
to modify files that have no current user or group ownership:sudo find /home -nouser -nogroup -exec sudo chown cloud_user:cloud_user {} ;
Check that we got them all:
find /home -nouser -a -nogroup -ls
See if
cloud_user
owns them now:find /home/devuser -ls