bash: ulimit: open files: cannot modify limit: Operation not permitted
An unprivileged shell can lower its soft limit or raise it up to the hard limit, but never past the hard limit. Running ulimit -n 65535 asks for more than the hard limit your session inherited. Editing limits.conf does nothing for services, which take their limits from systemd, and only applies to new logins via PAM, so the old shell keeps the old ceiling.
Quick fix
Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.
# Soft and hard limits for this shell
ulimit -Sn; ulimit -Hn
# Raise up to the hard limit, which needs no privilege
ulimit -n "$(ulimit -Hn)"
# For logins: raise both limits in limits.d, then log in again
echo '* soft nofile 65535' | sudo tee /etc/security/limits.d/90-nofile.conf
echo '* hard nofile 65535' | sudo tee -a /etc/security/limits.d/90-nofile.conf
# For a systemd service, limits.conf is ignored: use the unit
sudo systemctl edit myapp # add: [Service] LimitNOFILE=65535
sudo systemctl restart myapp
grep "open files" /proc/$(pidof myapp)/limits
How to diagnose Shell errors
Shell errors are usually about PATH, permissions, or quoting and expansion. The quoting class is the most damaging because it fails silently: an unquoted variable containing a space becomes two arguments, and an empty one disappears entirely. Running shellcheck over any script longer than a few lines catches most of these before they run.
If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.
- Trace execution with
bash -x script.shto see each command after expansion. This makes quoting bugs immediately visible. - Start every script with
set -euo pipefailso failures stop the script instead of cascading. - Quote every variable expansion:
"$var","${arr[@]}". This single habit prevents the majority of shell bugs. - Use
command -v footo check whether something is on PATH, andecho "$PATH"to see what the shell is actually searching. - In Makefiles, recipe lines must begin with a real tab character. "missing separator" always means spaces were used instead.
Tools worth reaching for
shellcheckbash -xset -euo pipefailcommand -vcat -A (to reveal tabs)
Authoritative references
Primary documentation for this error, worth reading before applying any fix in production.
Related Shell errors
- /usr/bin/env: 'python': No such file or directoryThe script's shebang asks for a command called python, and current Debian, Ubuntu, Fedora and…
- bash: !": event not foundIn an interactive shell, an exclamation mark in double quotes triggers history expansion, and…
- bash: [: : integer expression expectedA numeric comparison such as -gt or -eq got something that is not a whole number. The text…
- bash: [: too many argumentsA variable inside single brackets was left unquoted and its value contained spaces, or a glob…
- bash: $'\r': command not foundThe script has Windows line endings. Bash treats the carriage return as part of the last…
- bash: Argument list too longA glob expanded to more arguments than the kernel's exec limit allows. The limit is on the…
- bash: bad interpreter: No such file or directoryThe script's shebang line ends with a carriage return, so the kernel looks for an interpreter…
- bash: bad substitutionInvalid parameter expansion syntax. May be caused by using bash-specific syntax in sh, or…
Browse other categories
- HTTP 494xx client errors, 5xx server errors, redirects, headers and protocol problems.
- JavaScript 42npm resolution, async pitfalls, hydration, memory limits and runtime type…
- Database 41Connections, deadlocks, constraints, replication and memory limits.
- AI 35Rate limits, context windows, GPU memory and model-serving failures.
- Network 35Refused connections, timeouts, resets, MTU problems and port exhaustion.
- Python 35Imports, virtual environments, encoding, concurrency and dependency conflicts.
- Kubernetes 34CrashLoopBackOff, ImagePullBackOff, OOMKilled, RBAC, scheduling and storage.
- Docker 27Daemon connectivity, disk space, image pulls, ports and architecture mismatches.
- System 26Disk space, systemd units, file descriptors, OOM killer and scheduled jobs.
- Cloud 25IAM permissions, quotas, service limits and credential failures.
- Security 25JWT validation, CSRF, OAuth grants, SELinux, SSH host keys and CSP.
- TLS 24Untrusted authorities, expiry, hostname mismatch, chains and cipher negotiation.
Something missing or wrong?
This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.