Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6252979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:54:24+00:00 2026-05-24T13:54:24+00:00

I am trying to write file into /etc folder on Mac OS X. [[textView

  • 0

I am trying to write file into /etc folder on Mac OS X.

[[textView string] writeToFile:@"/etc/info.txt" atomically:YES encoding:NSUnicodeStringEncoding error:&error];

It throws error that I don’t have permission to write there ( naturally ), but I don’t understand how to get permission to be able to write into the System folders.

Also can somebody provide simple example?

Please help.
Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:54:26+00:00Added an answer on May 24, 2026 at 1:54 pm

    Okay, after researching quite a bit I believe I found a more/less simple method.
    First check out the link: Cocoa – Gaining Root Access for NSFileManager

    They suggest using already made class “BLAuthentication” – which takes care of lots of authentication coding for you. Google it to download, add to the project and use in your code. Here is a example of how simple that is:

    id blTmp = [BLAuthentication sharedInstance];
    
    NSString *myCommand = [[NSString alloc] initWithString:@"/bin/cp"];
    
    NSArray *para = [[NSArray alloc] initWithObjects:fileName, @"/etc/", nil];
    
    [blTmp authenticate:myCommand];
    
    if([blTmp isAuthenticated:myCommand] == true) {
        NSLog(@"Authenticated");
        [blTmp executeCommandSynced:myCommand withArgs:para];
    
    } else { NSLog(@"Not Authenticated"); }
    
    [fileName release];
    [myCommand release];
    [para release];
    

    Naturally above approach doesn’t exactly answers my own question, since with above example you don’t directly write to “/etc”. Instead first I have to write file to “/tmp” (or other directory of your choice) and then using “cp” command in unix, copy it over to “/etc” (using “BLAuthentication” for authentication).

    This is the simplest to do it, that I managed to find.

    *Note: This method might not work in Lion (Mac os 10.7) since “BLAuthentication” uses deprecated function “AuthorizationExecuteWithPrivileges”. Also I would suggest watching WWDC 2011 where they talk about security and proper ways of accomplishing the task. However if you need to prototype and/or play around, “BLAuthentication” should do the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a stored procedure that will read an Excel file into
I'm trying to write a 2d array into an output file, it's all working
I want to write data into the file in binary form. I was trying
I'm trying to write a file from an Http post reply to a file
I'm trying to write a log file from an ASP.NET application under IIS7, but
I'm trying to write a log file from an ASP.NET application under IIS7, but
I'm trying to write a batch file that takes the drive letter the batch
I'm trying to write a multi-file patch for an open-source project, but the master
I'm trying to write an INI file using the WritePrivateProfileString and WritePrivateProfileStruct functions. I
Trying to write a couple of functions that will encrypt or decrypt a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.