- Lab
- A Cloud Guru
Finding Files, and Assigning Permissions and Ownership
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.
Path Info
Table of Contents
-
Challenge
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. -
Challenge
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.
-
Challenge
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.
-
Challenge
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
-
Challenge
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
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.