我的Tomcat应用程序可以在Ubuntu服务器上写什么文件夹 [英] What Folder(s) Can My Tomcat Application Write To on Ubuntu Server

查看:171
本文介绍了我的Tomcat应用程序可以在Ubuntu服务器上写什么文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定在这种情况下我使用Ubuntu Server的事实是否重要。当我尝试使用File.mkdirs()方法创建文件夹时,它不会抛出异常,只是从不起作用。

I'm not sure if the fact that i'm using Ubuntu Server matters in this case. When I am trying to create folder using the File.mkdirs() method, it doesn't throw an exception, just never works.

对我的问题的更大解释具体的代码参考可以在这里找到:无法在服务器上创建目录。许可问题?

A larger explanation of my problem with specific code references can be found here: Cannot Create Directory On Server. Permission Issue?

我写一个新问题的原因是因为我想知道我是否在服务器上创建目录时遇到问题权限。

The reason i'm writing a new question is because i'm wondering if i'm having issues creating directories on the server because of permissions.

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

所以我正在尝试在/ home / username目录中创建一个文件夹。当我在我的开发盒上以及Eclipse内部的tomcat实例上以dev模式运行时,这很好用,但是当代码在服务器上运行时失败。这可能是因为在开发框中用户已登录,因此打开了写入/ home / username文件夹的权限?在服务器上,用户在程序运行时实际上没有登录...

So i'm trying to create a folder in the /home/username directory. This works just fine when i'm running in dev mode on my dev box and on a tomcat instance inside of Eclipse, but fails when the code is run on the server. Could this be because on the dev box the user is logged in and therefore permission is open to write the /home/username folder? On the server a user isn't actually logged in while the program is running...

我能写一个特定的文件夹吗?

Is there a specific folder I am able to write to?

我检查了当前设置为700的文件夹的权限。这可能是问题吗?将此文件夹设置为666或777是否安全?即使用户未登录,此文件夹是否可写?

I checked the permissions of the folder which are currently set to 700. Could that be the problem? Is it safe to set this folder to 666 or 777? Is this folder writable even if the user is not logged in?

更新:尝试将文件夹权限更改为755但没有运气。

Update: Tried changing the folder permissions to 755 with no luck.

推荐答案

如果您使用的是ubuntu的tomcat打包版本,则会在不同的用户帐户下运行 - 很可能名为tomcat。仔细检查 ps aux | grep catalina - 这将显示tomcat正在运行的用户名,如第一列中所示。确切地说,此用户帐户需要能够创建目录/文件。

If you're using ubuntu's packaged version of tomcat, this is running under a different user account - most likely named 'tomcat'. Double check with ps aux | grep catalina - this will display the username that tomcat is running as in the first column. Exactly this user account needs to be able to create the directories/files.

因此,您可能不希望打开任意主目录以进行全局编写,而是将某些特定目录配置为tomcat用户可以访问的位置。设置755权限赋予所有者读/写/执行权限,而其他人都获得读/执行权限。如果'tomcat'不是所有者,它将无法在这些目录中创建任何内容。但不要陷入陷阱 chmod 777 - 除非是快速测试。

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

这篇关于我的Tomcat应用程序可以在Ubuntu服务器上写什么文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆