Error: EACCES: permission denied

Asked

Viewed 688 times

0

My environment is Ubuntu and I’m having trouble accessing files that are inside a folder that is subfolder of my project folder. Here’s the code:

const httpsOptions = {
        cert: fs.readFileSync(path.join(__dirname, 'ssl', 'fullchain.pem')),
        key: fs.readFileSync(path.join(__dirname, 'ssl', 'privkey.pem'))
    };

    server = https.createServer(httpsOptions, app).listen(PORT, () =>{
        console.log("Server UP: " + ip.address() + ":" + PORT );
    });
}

The error returned is:

fs.js:646
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: EACCES: permission denied, open '/home/ubuntu/vienna-server/ssl/fullchain.pem'
    at Object.fs.openSync (fs.js:646:18)
    at Object.fs.readFileSync (fs.js:551:33)
    at Object.<anonymous> (/home/ubuntu/vienna-server/server.js:120:12)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)

I looked for similar solutions and nothing to solve my problem. I tried running the command sudo chmod -R 777 ubuntu ssl/* and unsuccessfully.

Some help, I’d really appreciate it.

  • This must be happening because your user does not own the file, do the following in the folder where this file is fullchain.pem execute ls -l see if in front of the file this something like root root, if that is the case then run sudo chown <seu user> <arquivo> this will make your user also own the file.

  • 1

    I usually use sudo before the command....

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.