Errno::EACCES
RubyERRORNotableFilesystem

Permission denied

Quick Answer

Check file permissions and the process user; use File.readable? / File.writable? before attempting access.

What this means

Raised when the process lacks the required OS permission to access a file, directory, socket, or other resource. Maps to POSIX errno 13 (EACCES).

Why it happens
  1. 1Attempting to write to a file owned by another user without write permission
  2. 2Opening a file in a directory the process has no execute (traverse) permission on
  3. 3Binding a privileged port (< 1024) without root/CAP_NET_BIND_SERVICE

Fix

Check permissions before access

Check permissions before access
path = '/etc/sensitive'
if File.readable?(path)
  File.read(path)
else
  raise "No read permission on #{path}"
end

Why this works

File.readable? performs a permission check without raising an exception.

Code examples
Reproducing the errorruby
File.open('/etc/shadow', 'r')
# Errno::EACCES: Permission denied - /etc/shadow
Check writable before writeruby
File.writable?(path) ? File.write(path, data) : warn('No write access')
Rescue permission errorruby
begin
  FileUtils.rm_rf(dir)
rescue Errno::EACCES => e
  puts "Permission denied: #{e.message}"
end
Sources
Official documentation ↗

Ruby Core Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Ruby errors