I'm running a program on a remote Linux Ubuntu server. This program accesses existing files from my directory, performs some calculations, writes new files to the directory then has to access the files it has created to perform some new calculations. The problem I have is that the first batch of files the program creates only have owner read permission - the program can't execute them and then times out with an error. Is there a way I can ensure that every file written to my directory automatically has public read, write and execute permissions (rwxrwxrwx)? I can't modify the program script in anyway and I can't stop the program once its started so my only option is to do this via Linux.

I did have a look at previous questions but I couldn't see anything that dealt with this particular problem.

Thanks in advance for any suggestions :)

  • You can give permission while creating the file and even after file has been created but as you said you can't change the program which is creating the newer files, you can either write an another new shell script which changes file's permission or use command line instead. I don't find this question is unique from previous questions. Can you tell more clearly, what have you tried?
    – Baba Rocks
    Apr 16, 2017 at 4:21
  • Hi Baba Rocks, thanks for your reply. Perhaps, as I'm quite new to this, I haven't searched with the right terminology. I've now been working with the umask and chmod commands and managed to set the write permissions for new directories but not the files within those directories. However, I have a .profile file within my directory which has a umask value set and which I do not have permission to edit. I think I'll have to get in touch with the IT department and have them change the file permissions on my directory.
    – Magpie101
    Apr 16, 2017 at 18:24

1 Answer 1


There are several ways to achieve what you describe using the shell, but it all comes down at what exaclty are you after and what level of access you have to the folders in question and shell access.

As I understand you want to change the behavior of the server respect to these new generated files. But it depends on the user running the script or aplication, their relation to the user of the shell or ftp... the fact is what we really know about your problem is not yet complete.

You could, for example, give the ownership of the folder to the app user, but it could make problems with the shell user or ftp user if they are not the same.

For this you can use:

chown -R user:group /[path-to]/myfolder

where [path-to] is should be changed to the path of the folder and myfolder to the actual folder on the machine, user and group should be changed respectively to the user and group of the user that runs the app or script. If your folder was for example "app" and is on the /var/www/ path on the remote machine, and the app is run by www-data user, then it should be then

chown -R www-data:www-data /var/www/app

But as I say, little we know about the specifics. So it could be that the problem is generated by a strict policy by the server administrator where the umask something like:

umask 333 or even worst umask 377

where the resulting permissions are something like r--r--r-- or r-------- but to deal with these you can put a temporary umask in your app, or set it on the env for the user of the app... but I really think this is really unprobable.(tell me if you need something like this to expand on this option)

another way is not granting entirely the ownership to the app user, but to use a group the app user belongs to and enable the s flag to allow every file in the directory to be automatically created with special grant permissions on the group.

first change the group ownership of the folder, like:

chown -R sameuser:newgroup /[path-to]/myfolder

then change the sgid bit of the folder

chmod g+s /[path-to]/myfolder

more about sgid on http://www.linuxnix.com/sgid-set-sgid-linuxunix/

SGID (Set Group ID up on execution) is a special type of file permissions given to a file/folder. Normally in Linux/Unix when a program runs, it inherits access permissions from the logged in user. SGID is defined as giving temporary permissions to a user to run a program/file with the permissions of the file group permissions to become member of that group to execute the file. In simple words users will get file Group’s permissions when executing a Folder/file/program/command.

But anyway, if i'm missing your point, consider that sometimes it helps to know a little bit more about the problem in question. Consider expanding your question a little with some other relevant information (like what kind of app, what you mean about solving with linux, like what user runs your app or do you even have shell access?)

Hope it helps anyway.

  • Hi, the umask and chmod commands did help. As the above comment it looks like some of my capabilities to change write permissions are restricted, so I'll have to get the server administrators to help with this. However, thanks ever so much for the info - it's very useful for future reference.
    – Magpie101
    Apr 16, 2017 at 18:26
  • Do you want me to expand a bit the info on the umask? cause if you are able to use umask in your script you could cirvumvent the restriction for writing on the newly created files...but I still think we don't know much about your problem. The umask you mention on your comment is a restrictive one? cause if it is like 222 or something permissive that means you may be able to work with sgids...
    – t3nshi
    Apr 17, 2017 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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