Home
Software
TIL
Contact Me
Increase open file limit on Ubuntu Linux

What and why of open file limit

If you run a webapp on a Linux server, your webapp needs to open files and make network connections.
Most Linux servers have horrible default for this and limit the number of opened files at the same time to e.g. 1024.
To check the limit run: ulimit -n.
1024 makes sense if it’s a shared computer used by multiple users, to protect the system from abusive user. It doesn’t make sense if the server is used for running a web app which can run into this limit and silently fail because it can’t open a file or a network connection.
What is a reasonable limit? No one knows but I set mine high, to at least 65 thousand. The more RAM you have, the higher the limit can be. It also depends on your app: if it opens a lot of files and network connections, you need higher limit.

How to change open file limit on Ubuntu

1. Edit the system limits configuration:
sudo nano /etc/security/limits.conf
2. Add at the end of file:
*       soft    nofile  65535
*       hard    nofile  65535
3. Edit PAM configuration file:
sudo nano /etc/pam.d/common-session
4. Add at the end of file:
session required pam_limits.so
5. Edit the limits configuration file for systemd:
sudo nano /etc/systemd/system.conf
6. Add at the end of file:
DefaultLimitNOFILE=65535
7. Reboot:
sudo reboot
It’s way too complicated but that’s Linux for you.
til devops
Jul 7 2025

Home
Software
TIL
Contact Me