HB Computer Security | Aide Memoire
  • Introduction
  • Core Technical Skills
    • Core Skills
      • Linux
        • Getting to Know Linux
          • Using the Shell
            • Shells, Terminals, and Virtual Consoles
            • Choose your Shell
            • Shell Commands
              • Non-PATH Commands
              • Command History
                • Command Line Editing
                  • Keystrokes for Navigating Command Lines
                  • Keystrokes for Editing Command Lines
                  • Keystrokes for Cutting and Pasting Text from within Command Lines
                • Command Line Recall
                  • Keystrokes for Command Line Recall
              • Connecting and Expanding Commands
                • Piping Between Commands
                • Sequential Commands
                • Expanding Commands
            • Shell Variables
              • Common Shell Variables
            • Aliases
            • Create your Own Shell Environment
              • Modification Ideas
          • Navigating the Linux File System (LFS)
            • Filesystem Commands
            • Listing Files and Directories
            • File Permissions and Ownership
              • Modifying Permissions with chmod
              • Modifying Default Permissions with umask
              • Change File Ownership with chown
            • Copying, Moving, and Removing Files
            • Finding Files
              • locate
              • find
              • grep
            • Downloading Files
              • axel
              • wget
              • curl
                • User-Agent: Googlebot
          • Working with Text Files
            • Using vim and vi to Edit Text Files
              • Starting with vi
              • Adding Text
              • Moving Around in the Text
            • Text Manipulation
        • System Administration
          • Installing Linux
            • Installing from Live Media
            • Installing in the Enterprise
            • Partitioning Hard Disks
              • Tips for Creating Partitions
          • Account Administration
            • The root Account
              • Becoming root with su
              • sudo
                • The /etc/sudoers File
                • Granting sudo privileges
                  • visudo Guidance
                • Useful sudo Hints
            • Other Administrative Accounts
            • Standard User Accounts
              • Risks of userdel: Orphaned Files
          • Graphical Remote Administration
            • Cockpit
              • Installation Guide
            • Remote Desktop Protocol with xrdp
              • Installation and Configuration
            • Remote Desktop with vnc
              • Installation and Configuration
              • Running VNC as a System Service
          • Managing Running Processes
            • Listing Processes
              • ps
              • top
              • htop
            • Backgrounding and Foregrounding
              • Starting a Background Process
              • Using Foreground and Background Commands
            • Killing and Recining Processes
              • kill and killall
          • Managing Software
            • Managing Software from the Desktop
            • Going Beyond the Limitations of Software Center
              • Debian Packages
                • Advanced Package Tool (apt)
                • Repositories
                • dpkg
        • Shell Scripting
          • Variables
            • Command Substitution
            • Arguments
          • Reading User Input
          • if, else, and elif
          • BOOLEAN Logic
          • Loops
            • for Loops
            • while Loops
          • Functions
          • Local Vs Global Variables
          • Summary
        • Securing Linux
      • Windows
        • Security Hardening
Powered by GitBook
On this page

Was this helpful?

  1. Core Technical Skills
  2. Core Skills
  3. Linux
  4. Getting to Know Linux
  5. Navigating the Linux File System (LFS)
  6. File Permissions and Ownership

Change File Ownership with chown

If you want to change the owner of a file or directory, you can use the chown command. The syntax is as follows:

chown DESIRED_OWNER PATH/TO/FILE

It is important to understand that as a regular user, you cannot change ownership of files or directories to have them belong to another user. However, the root account can. Consider the following example.

Let's suppose that you created a file called memo.txt in the user chris’s home directory while you were root user. Here’s how you, as root, could change it to be owned by chris:

chown chris /home/chris/memo.txt

This will change ownership of memo.txt to chris. However, this does not change the group owner, merely the user owner. If you wanted to change the group owner at the same time, you could have entered:

chown chris:chris /home/chris/memo.txt

Now, the file is also owned by the group joe.

When a new user is created, it is typical for a group to be created of the same name. This is because Linux requires users to be a member of at least one group, referred to as their primary group, as part of its security and access control model.

The chown command can also be employed recursively with the help of the -R option. This is particularly useful when you need to modify the ownership of an entire directory structure to be owned by a specific user. For instance, if you've connected a USB drive, mounted it on the /media/myusb directory, and wish to grant complete ownership of the drive's contents to the user chris, you can execute the following command:

chown -R chris:chris /media/myusb
PreviousModifying Default Permissions with umaskNextCopying, Moving, and Removing Files

Last updated 1 year ago

Was this helpful?