How to Change File Ownership in Mac OS X

Apr 23, 2013 - 10 Comments

User icon Though it’s somewhat rare to encounter ownership and permissions errors in Mac OS X, it can happen, particularly when an account has been moved, or a files owner has been modified by a third party application. Oftentimes you can just run through the process to repair user permissions, but that’s not always guaranteed to sort out a problem, and in some situations you need to adjust a files ownership directly on either a single document or a group of files before the intended user will regain proper access to the file. For these situations, there are two ways to manually change a files ownership, through the Finder and also through the command line. We’ll cover both, though for more advanced users the chown command is really much faster, and in some respects, it can be easier too.

Changing a Files Ownership through Finder in Mac OS X

You can change a files ownership through the same Get Info panel that lets you adjust permissions in the Mac OS X Finder:

  • Select the file in the Finder, then hit Command+i to summon the “Get Info” window
  • Click the arrow alongside “Sharing & Permissions” to reveal the ownership and permissions options
  • Select the lock icon to unlock preferences
  • Click the [+] button to add a new owner, then add the user from the list and choose “Select”
  • Now select the name and click the gear icon, selecting “Make (username) the owner”

Change file ownership in Mac OS X

While going through the Finder is undoubtedly easy, it’s still several steps long and the Terminal can be faster in many ways. Don’t be intimidated by a command prompt, we’ll walk through the process and as you’ll see it’s actually pretty simple.

Change File Ownership with chown from the Command Line

Using the command line is generally considered more advanced, but for some situations it’s not only faster than going through the graphical interface, but in some regards it’s easier too. Here we’ll walk through the basics of changing file owners through the ‘chown’ command, which is standard in Mac OS X and also nearly all variations of unix.

Launch Terminal from /Applications/Utilities/ to get started.

The syntax in it’s simplest form is:

chown [username] [file]

For a usage example, to change the ownership of a file named “test-file.txt” to the user “Bob” the command would be:

chown Bob test-file.txt

Keep in mind that the user name you’re looking to use is the account short name, which is usually what a home directory is named after. If you’re not sure what the short user name is, type ‘whoami’ into the terminal to get the current short name, or type “ls /Users” to see a list of all user accounts on the current Mac.

Change a file owner from the command line with chown

If you’re altering a system files ownership or another users files that you don’t have read and write access to, you can always proceed chown with ‘sudo’ to use chown as super user and force the change:

sudo chown bob ~/Desktop/test-file.txt

Typically you won’t need to change the group of a file, but you can do that with chown as well by appending it to the desired username with a colon like this:

sudo chown bob:staff ~/Desktop/test-file.txt

Again, you usually won’t need to change the files group, though occasionally you will run into a file that has somehow lost or misappropriated both it’s owning user and the access level group it once belonged to.

In Mac OS X, the group is usually either ‘staff’ for general user files that are not admin level, ‘admin’ for administrative level user files like applications, preferences, and connected drives, and ‘wheel’ for superuser access to core OS components like /bin, /library, /home, /etc, /usr/, etc

Anyway, use whichever method is right for your needs, but for almost all cases of adjusting file ownership these days I launch the Terminal and use chown. That’s mostly a matter of preference, but I’ve never been a giant fan of the Get Info panels handling of ownership, though it’s usually fine for making quick adjustments to permissions.

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS

10 Comments

» Comments RSS Feed

  1. Ford5t3r says:

    Hi,
    I have a hard drive that I used with Lion, but now I have reverted back to Snow Leopard, as I was having issues with Logic Pro 9.
    Files that I transfered to the said hard drive, will not let me delete the files as they are locked and I don’t have permissions.
    I tried both ways outlined in the help article, but the ‘Get Info’ would not let me add my name to the privilege list, and the terminal keeps saying ‘Operation not permitted’
    .

    Can you please help

    Cheers
    Ford5t3r

    • pablo says:

      Try repairing the permissions on the external hard drive that is giving you the permissions error, that should do the trick. You can repair Permissions in Disk Utility for those versions of Mac OS X

      Because the errors you are encountering are broad it’s likely a broad permissions issue which is why Repair Permissions may be the solution. Later versions of MacOS removed the direct ability to repair permissions however.

  2. Rachit Anand says:

    Hi,

    I am trying to change the owner of the /user/lib folder. I have subfolders under this that I need to write to while installing stuff, and I am not able to do so, as I do not have permissions to write to the sub folders, and it is not allowing me to change the permissions of the sub folders as I am not the owner.

    I tried changing the owner of the lib folder in the terminal using the command below

    sudo chown rachitanand lib

    It asked for my password, and still gave me an “Operation not Permitted” error.

    In the Info about the folder, it says the system has R&W, wheel has R and everyone has R.

    Any help will be greatly appreciated.

    Thanks,
    Rachit

    • Paul says:

      It’s likely that you are running into SIP protection on those system directories, which are preventing you from having the ability to modify or change ownership of files or folders in those protected areas of Mac OS. You really should not be modifying /usr/lib/ or any other system level folder, things can go very wrong.

      With that said, you can disable SIP if you need to make system level modifications:

      https://osxdaily.com/2015/10/05/disable-rootless-system-integrity-protection-mac-os-x/

      Just be cautious, and backup your Mac first, as disabling SIP allows for unfettered modification of system components, which can render a Mac inoperable if something is haphazard or erroneous.

      Perhaps a good question is, what exactly are you trying to modify or accomplish? Are you trying to manually install command line software or something else?

  3. AL says:

    will this cmd change the ownership of the home folder to the current user?

    $ sudo chown -R $USER ~$USER

    If so, does the $USER = $USER or the actual user name?

  4. Felipe Lazo says:

    Super useful. I was handed a Mac for work and for some reason Terminal wasn’t saving my preferences (closing shell if exited cleanly and Pro as default theme). It’s not a common thing so I couldn’t find anything in Google. A guy found that the issue was that com.apple.Terminal.plist inside my preferences folder was owned by root and not by me. Another guy showed me that I can run sudo commands. Used both things, the command showed here for changing owner, and voilá.

    A million thanks!

  5. Roy says:

    To use chown recursively (in a directory and all files in all directories underneath):
    chown -R

    Eg.: to reassign ownership to the current directory and all the directories and files in this directory:
    chown -R .

    The period stands for the current directory.

  6. David Reed says:

    Wonder stuff. Thank you. Question: How and why is there a four-leaf clover in your terminal command window?

    Cheers!

  7. Dan says:

    This should be a pretty rare thing these days, especially now that OS X 10.8 has the “Duplicate Files Exactly” feature now that maintains both ownership and permissions, even if files are outside of the reach of the user.

    https://osxdaily.com/2012/03/10/maintain-file-ownership-permissions-when-copying-with-duplicate-exactly-in-os-x/

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site