HOWTO: Have Multiple Users Share an iTunes Library on One Machine

I recently purchased a new MacBook (never having owned a Mac before), and have been reading up on keeping things secure. Per one of those security-related suggestions, once everything was set up to my liking, I stopped using the admin account for everyday use and started forcing myself to log in as a regular user. I’ve also created a user account for my live-in girlfriend so she can go wild customizing her desktop with pictures of flowers, Hugh Jackman, Hugh Jackman laying in a bed of flowers, and so on, without making my eyes bleed.

The trouble is, we both buy music from iTunes on a regular basis using our own individual Apple ID accounts, and there isn’t an easy way to share our music seamlessly with one another. We have similar tastes in music and we’d like it so that when one person buys a new song, it is immediately available for the other person to listen to. Ideally, we’d also be able to create our own unique playlists and assign ratings to the various songs to reflect our own personal likes/dislikes. This article lays out the details of how I accomplished that goal…

The Problem

The main problem with assigning two iTunes Libraries to the same location comes down to permissions. By default, when you download music through iTunes, it assigns permissions based on the user that’s logged in. It only allows that user and people in the UNIX group “wheel” to read the music file (if you’re UNIX-literate, that means it has 640 file permissions). Since a different user (in this case, my girlfriend) would not fit into those categories, she doesn’t have the proper permissions to read any of the music I download. To put it simply…music needs to be world readable.

The Solution

These permissions can be easily fixed by running a simple script that uses the chmod command to modify your music so anyone can play it. To give you a breakdown, the script runs a few safety checks to ensure that you have the proper permissions to modify the files, it then checks that your specified library actually exists, and then it recursively looks at all of your music making sure it is world readable.

The trick is getting the script to run only when necessary as not to waste resources. You could set up a cron job, but then it would have to run on a fixed time table. Either it would run more often than necessary, or not often enough…so cron is out. You could set up a launchd/launchctl configuration file and specify it to run when your Library folder is modified, but unfortunately that doesn’t get triggered when a sub-folder gets modified…so launchd is out.

The key ends up being something called a “LoginHook” that is configured in the /etc/ttys file. Creating a LoginHook will ensure that whenever any user logs in to the machine, the script will be run and proper permissions will be set on the entire library.

Putting it All Together

This should go without saying, but I’m saying it…back up all of your music files before doing anything else! Once that’s done, proceed with the following steps:

  1. First you must pick a centralized location that all your users have access to and make sure the directory exists. I picked /Users/Shared/Music/iTunes and created it on the command-line using:
    mkdir -p /Users/Shared/Music/iTunes
  2. Next, you must adjust your iTunes settings to point to the new location. You do this by launching iTunes, then navigate to iTunes » Preferences… » Advanced, and under the General tab, click the Change… button next to the “iTunes Music folder location” box. Navigate to your newly-created centralized folder (in my case /Users/Shared/Music/iTunes), and click Choose.
  3. For ease of maintenance and to prevent duplicate files from being generated, make sure the checkbox labeled “Copy files to iTunes Music folder when adding to library” is not selected (this is also under the Advanced section of the Preferences dialog box).
  4. Click OK to accept the changes you made to your preferences.
  5. To copy your current library to the new location, navigate to Advanced » Consolidate Library… then proceed by clicking Consolidate. This step only needs to be performed one time per user to ensure that everything gets moved over to the new location.
  6. Repeat these configuration steps for all users that you wish to consolidate libraries for.

At this point, you’ve done all that is necessary to do within iTunes, and all that is left is fixing the file permissions. To do that, log in as a user with administrator privileges and follow these steps:

  1. Download the script and put it anywhere you want. I made another directory called /Users/Shared/bin/ and put the script there, but the location doesn’t really matter.
  2. Modify the script’s LIBRARY variable (in the CONSTANTS section) to point to the centralized music directory you created above.
  3. Ensure that the script is executable by running:
    chmod 755 /Users/Shared/bin/share-itunes
  4. Then edit the /etc/ttys file with your favorite text editor, and change the line starting with “console” to add:
    -LoginHook /Users/Shared/bin/share-itunes
    right after the “loginwindow” declaration. Make sure you actually point it to the location where you downloaded the script to. The line should have looked something like this before you edited it:

    console "/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow" vt100 on secure onoption="/usr/libexec/getty std.9600"

    …and look like this after you edit it:

    console "/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow -LoginHook /Users/Shared/bin/share-itunes" vt100 on secure onoption="/usr/libexec/getty std.9600"
  5. Save the file, and close your text editor.

That’s it! Everything should be all set to go and your permissions will be checked each time you log in to the computer.

Caveats

The only thing I wasn’t able to automate was adding new music purchased by my girlfriend in to my library so it actually shows up when I launch iTunes. For all I know, there may be an easy way to automate it, but I haven’t found one at this time. Luckily it’s a fast/easy procedure to do by hand…

To actually have new music purchased by another user show up in your library, all you have to do is launch iTunes, go to File » Add to Library…, then navigate to your shared music folder and click Choose. It will take a few seconds to parse through your library, but after it’s done, all of the music should be available for you to play. You will have to do that every time you know that music has been added by another user, but everything else should be automated for you.

Why it Works

Unless you get tricky, iTunes always stores your album artwork, playlists, and song rating information in a file under your home directory (well, in ~/Music/iTunes, to be precise). It also stores a meta file with information regarding what it thinks should be included in your library. These files will be unique to the user even if you choose to share your actual music collections. So when you update your iTunes preferences to move the location of your Library, you still retain the ability to have all your own custom settings regardless of what other users add to the common music folder.

By periodically telling iTunes to add the common music directory in to your library, you’re simply forcing it to update the library meta file so it reflects whatever actually exists in that directory…regardless of whether or not you were the person to purchase the music.

Hopefully these steps will be able to help someone else out there having a similar issue. When I first started looking in to how to accomplish this configuration, I though surely it would be easy and done before, but alas, things got a bit more complicated than I had hoped. If you know of a better way, please do leave a comment and let us know what works for you. If you have any trouble understanding these procedures or getting it to work, let me know and I’ll see what I can do to help out…happy listening!

  • None Found

15 Comments

  1. Posted April 30th, 2007 at 12:55pm | Permalink

    Excellent Job – Great article.

    Submitted in queue @ tweako
    ( http://www.tweako.com )

  2. Ian Zlatkiss
    Posted June 30th, 2007 at 12:00pm | Permalink

    I am having trouble getting command teminal to verify the location of the file. Using the command in the article “chmod 755 /Us……bin/share-itunes” I get a “no such file” error. Could it be beacuse my Hard drive is partitioned for OS X and Windows XP? (I have a Mac g5) Those are the names of the 2 partions on my hard drive. ANy ideas?

  3. Posted July 6th, 2007 at 9:14am | Permalink

    yes, get a PC! joking….

  4. Seth
    Posted July 20th, 2007 at 6:28am | Permalink

    Ian, having a partitioned drive shouldn’t effect this at all, since the partitions are identified in /Volumes which we don’t go near.What your error message says is that it can’t find the script. Possible problems: you forgot to save the script in the location you are pointing at, or you mistyped the location.Remember that OS X is case-sensitive, make sure it is perfect.Beyond that, it is hard to tell from the little you have told us.

  5. Posted August 1st, 2007 at 8:32pm | Permalink

    In IE7 your homepage looks wonky, everything is pushed to the left, in FF 2.0.0.4 it’s a bit better but still has a huge scroll.
    hth Tina

  6. Posted August 12th, 2007 at 11:42am | Permalink

    I was trying to do the same thing as you. I do software development, and I don’t like having to put up with my development environment when I just want to do something simple, like check my email or listen to music. I did the same thing as you, minus the login script, but I had the same caveats as you. I figured out a slightly more elegant solution — symbolic links. The process is pretty much the same, except you don’t have to change the path to your library in iTunes.

    Here’s how:

    1. Move your music to a shared folder (I used the same location as you)

    2. Change the permissions on the library to be world readable (or at least readable by a common group of whoever will be using the library).

    3. Make sure there is no longer an iTunes directory in /Users/username/Music. Do this for every user that will be sharing the library.

    4. Open terminal, and type the following:
    ln -s /Users/Shared/Music/iTunes ~/Music/iTunes
    Also do this for every user that will be using the library

    Now you don’t have to worry about doing “File -> Add to library . . .” every time new music is added. There’s one new caveat though. Because iTunes is basically reading from the shared folder, if more than one user tries to use iTunes at the same time (if you’re using fast user switching for example), you will see a “file locked” error. This is normal, and the only fix I know of would be to put the library on some sort of a network share like NFS or ZFS.

  7. Posted August 12th, 2007 at 3:12pm | Permalink

    Using symbolic links would also get rid of the ability to have your own unique ratings and playlists, since you would be accessing the same meta data for all users. Since that was one of my initial requirements, I went with the way I laid out above, and just deal with the caveat of having to run “Add to Library…” when other users add music. Once things are set up, it’s about as transparent as you can get from an end-user standpoint.

  8. sal
    Posted September 3rd, 2007 at 9:36pm | Permalink

    “To move your current library to the new location, navigate to Advanced » Consolidate Library…then proceed by clicking Consolidate. This step only needs to be performed one time per user to ensure that everything gets moved over to the new location.”

    It’s seems as though it just copied everything…? Once I ensure everything got moved, I look in my original directory ~/Music and everything is still there…

    any thoughts??

  9. Tom Harris
    Posted May 1st, 2008 at 5:49pm | Permalink

    In response to John’s comment about using symbolic links to share the library, and the author’s response, I suppose the inability to maintain separate playlists, ratings, etc. could be overcome while maintaining the elegance of the symbolic link approach by only symbolically linking the ‘iTunes Music’ and ‘Album Artwork’ directories within each user’s iTunes folder to the shared music folder. I am currently setting up a shared music directory on a shared drive utilizing an Airport Extreme sharing some USB drives. I’ll dedicate one of the drives as shared space to contain the shared ‘iTunes Music’ directory and shared ‘Album Artwork’ directories and then create symbolic links in each user’s home folder on each computer in the house to those folders (for the macs at least — I haven’t looked into how the PC will treat the situation). I have no experience, however, creating symbolic links to networked drives and wonder 1) will there be any issues when iTunes is used when the shared drives are not mounted (the macs are notebooks), and 2) will there be file-locking issues (the shared drives will be HFS+ formatted shared over AFP). Any feedback would be appreciated.

  10. Peter
    Posted May 2nd, 2008 at 3:19am | Permalink

    An alternative to running the script regularly, might be to use netinfo manager or the dscl command to make another group called “music” and make all required users members of that group. Alternatively just use an existing group such as staff and add users to that. Then you simply change the owner group and permissions using:
    chown phil:staff -R /Users/Shared/Music
    chmod -R 775 /Users/Shared/Music
    The above assumes that your main admin user is phil and the group you choose is staff. You end up with file permissions of rwxrwxr-x for all files.

  11. borstenwurm
    Posted May 19th, 2008 at 12:56pm | Permalink

    great article! i haven’t had the time to try it myself, but it sounds great and i was looking for a solution for this for quite a while. so thanks in advance!

  12. Alex
    Posted December 18th, 2008 at 2:55pm | Permalink

    Great article! I’m trying to implement it however I cannot edit the ttys file. I changed the priviledge of everyone to read/write but I still can’t save the edited file. I am an administrator-level user.
    Thanks!

  13. Posted December 19th, 2008 at 12:46am | Permalink

    “I’m trying to implement it however I cannot edit the ttys file. I changed the priviledge of everyone to read/write but I still can’t save the edited file. I am an administrator-level user.”
    –Alex

    Even if you are an administrative-level user on OS X, certain system files are still owned by root:

    $ ls -l /etc/ttys
    -rw-r--r--  1 root  wheel   1.4K Jan 28  2008 /etc/ttys
    

    So you’ll have to use either sudo or su in order to gain the privileges to edit the file:

    $ sudo vim /etc/ttys

    If you meant that you ran chmod on the file and set permissions to 666, then I’m not sure why that didn’t work without investigating further. Did you do that as root?

  14. julien
    Posted March 29th, 2009 at 12:07pm | Permalink

    I got around all this Unix permissions stuff by having the ‘master’ itunes music folder on my external drive with the folder name “iTunes”. I then (as an administrator) gave “Everyone” Read and Write access to this folder applying this to enclosed items using Get Info on the folder. Next I replaced the iTunes folder in my Music folder with an alias to the folder on the external drive called “iTunes”, as did all the other users on the computer. Now we can all access the music and add to it as we want. The only downside I guess is that we all see all Playlists, so I have my 10-year old daughter’s playlists on my iPod too!

  15. dan
    Posted October 25th, 2009 at 10:31am | Permalink

    modified the tty file…but now I do not get the log in screen (list of users) when I start up the computer…just a pretty blue screen…I’ll have to use the startup disk and undo my edits to the file…any ideas? I’m on Mac OSX 2.4

Post a Comment

Your email address is never published nor shared. Required fields are marked *

*
*