Skip to main content

Finding User Files and Reassigning Permissions in Linux

Hands-On Lab

 

Photo of Terrence Cox

Terrence Cox

Senior Vice President of Content

Length

00:30:00

Difficulty

Beginner

Managing files and the users that own them is a key skill for any system administrator to have. In this activity, the student will be using the Linux command line to find files that are owned by a specific user no longer on the system and then automatically reassign them to a new user. At the end of this scenario, the student will have a firm grasp of how to use the 'find' command to manage files in addition to just finding them. Note: chown [new-owner]:[new-group] [file-name]

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Finding User Files and Reassigning Permissions in Linux

Use find to Locate Files

Before we can modify any file permissions, we've got to know which files need modifying. To find the files owned by the jtodd user, let's run:

[cloud_user@host]$ sudo find / -user jtodd

Change Ownership of the Files

Now that we know where the files are, we can change ownership of them from jtodd to cloud_user. It looks like /opt/myapp contains a lot of files he owns, so let's start by changing that:

[cloud_user@host]$ sudo chown -R cloud_user:cloud_user /opt/myapp

If we run ls -l /opt/myapp, we can see the cloud_user user and group own the directory now.

Check for More Files and Change Them

We can run the find command again to see what's left to change. There will be a few more things, like jtodds's home directory and some mail. We can fix those with these two commands:

[cloud_user@host]$ sudo chown -R cloud_user:cloud_user /home/jtodd
[cloud_user@host]$ sudo chown -R cloud_user:cloud_user /var/spool/mail/jtodd

We can run the find command again to check, but at this point it looks like we've got them all.

Conclusion

You're all set. Congratulations on completing this lab!