Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

so I'm completely new to Ubuntu. I've set up a shared folder with a few c programs and when I go to compile in Ubuntu, such as:

gcc file.c -o fileTest

I get the following error:

/usr/bin/ld: cannot open output file fileTest: Permission denied
collect2: error: ld returned 1 exit status

I'm sure that my permissions for the C files are correct, all files have 'rwx' permissions.

Do I have to change the permission of the directory as well?

I'm a complete newb, so apologies.

share|improve this question
up vote 4 down vote accepted

Yes, you have to change the permissions of the directory as well.

This is because if you only have write permissions to the files inside the directory, you can't just create a new file because you don't have write permissions for that file (it doesn't exist, so no permissions to create it).

If you have write permissions for the directory you can create a file inside it because you have write permissions for the directory itself.

To make yourself the owner (terminal way):

  1. Check your user name:

  2. Make yourself the owner of the directory and its contents:

    sudo chown -R username:username /path/to/the/directory

    Replace username by your actual username.

    The -R flag stands for recursive, so that directory and all its subfiles and subdirectories will change owner. Remove the -R flag to just change the permissions of the directory itself.

Now you should be able to create files or directories because you're now the owner of the directory and all its content. If you still can't, give the owner write permissions to the directory and its content using the following command:

chmod -R 700 /path/to/the/directory
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.