sudo usermod -aG www-data hongrui
sudo chown -R hongrui:www-data /opt/report
sudo chmod -R 0750 /opt/report
配置后nginx可以下载
-rw-r--r-- 1 hongrui hongrui 13 Mar 13 16:18 perm.log
配置后nginx可以下载
-rw-r--r-- 1 hongrui hongrui 13 Mar 13 16:18 perm.log
这样的文件
但是无法下载
-rw-r----- 1 hongrui hongrui 13 Mar 13 17:47 perm.log
但是无法下载
-rw-r----- 1 hongrui hongrui 13 Mar 13 17:47 perm.log
一下代码在使用java的Main函数可以调用
但是在tomcat中出现出现异常,
经确认发现其上传目录下代码自动创建的目录权限是750,所上传文件权限是640。也就是说默认赋予的文件权限中其他用户的权限始终为0所导致。umask 002 对应文件权限664,文件夹权限775;umask 022对应文件权限644,文件夹权限755。可见都有读取访问权限的。在默认情况下,tomcat所建目录及文件应该用到的是umask 022.
在tomcat 8.5的catalina.sh中,UMASK=”0027”出现了!在按照目前的功能需求,将其改为UMASK=”0022”并重启tomcat 8.5后,文件访问恢复正常。
点击(此处)折叠或打开
- package test;
- import static java.nio.file.StandardOpenOption.*;
- import java.nio.*;
- import java.nio.channels.*;
- import java.nio.file.*;
- import java.nio.file.attribute.*;
- import java.io.*;
- import java.util.*;
- public class LogFilePermissionsTest {
- public static void main(String[] args) {
- // Create the set of options for appending to the file.
- Set<OpenOption> options = new HashSet<OpenOption>();
- options.add(APPEND);
- options.add(CREATE);
- // Create the custom permissions attribute.
- Set<PosixFilePermission> perms =
- PosixFilePermissions.fromString("rw-r--r--");
- FileAttribute<Set<PosixFilePermission>> attr =
- PosixFilePermissions.asFileAttribute(perms);
- // Convert the string to a ByteBuffer.
- String s = "Hello World! ";
- byte data[] = s.getBytes();
- ByteBuffer bb = ByteBuffer.wrap(data);
- Path file = Paths.get("/opt/report/perm.log");
- try (SeekableByteChannel sbc =
- Files.newByteChannel(file, options, attr)) {
- sbc.write(bb);
- } catch (IOException x) {
- System.out.println("Exception thrown: " + x);
- }
- }
- }
经确认发现其上传目录下代码自动创建的目录权限是750,所上传文件权限是640。也就是说默认赋予的文件权限中其他用户的权限始终为0所导致。umask 002 对应文件权限664,文件夹权限775;umask 022对应文件权限644,文件夹权限755。可见都有读取访问权限的。在默认情况下,tomcat所建目录及文件应该用到的是umask 022.
在tomcat 8.5的catalina.sh中,UMASK=”0027”出现了!在按照目前的功能需求,将其改为UMASK=”0022”并重启tomcat 8.5后,文件访问恢复正常。