Which folder can Tomcat use to write on an Ubuntu server?

I'm not sure if the fact that I'm using a Ubuntu server matters. When I try to create a folder using the File.mkdirs () method, it does not throw an exception, it just never works.

A more detailed description of my problem with specific code links can be found here: Unable to create a directory on the server. Problem with resolution?

The reason I'm writing a new question is because I am wondering if I have problems creating directories on the server due to permissions.

String path = /home/username/foldertocreate; File file = new File(path); file.mkdirs(); 

So, I'm trying to create a folder in the / home / username directory. This works fine when I run in dev mode in my dev block and in the tomcat instance inside Eclipse, but does not work when the code runs on the server. Could this be due to the fact that the user is logged in in the dev block, and therefore it is allowed to open the / home / username folder? On the server, the user is not actually logged in while the program is running ...

Is there a specific folder that I can write to?

I checked permissions for the folder that is currently set to 700. Could this be a problem? Is it safe to set this folder to 666 or 777? Is this folder accessible even if the user is not registered?

Update: I tried changing the permissions of the folder to 755 without any luck.

+6
source share
1 answer

If you are using the batch version of tomcat ubuntu, it works under a different user account, most likely with the name "tomcat". Double check with ps aux | grep catalina ps aux | grep catalina - this will display the name of the user who runs tomcat, as in the first column. It is this user account that should be able to create directories / files.

For this reason, you probably do not want to open arbitrary home directories for writing to the whole world, but rather configure certain directories somewhere to access the tomcat user. Setting permission 755 gives owners read / write / execute permissions, while everyone else gets read / execute permissions. If "tomcat" is not the owner, it will not be able to create anything in these directories. But don't fall into the chmod 777 trap - unless it's for a quick test.

+6
source

Source: https://habr.com/ru/post/945861/


All Articles