Set Permanently ulimit -n / open files in ubuntu

Last Updated on March 8, 2024

The currently configured system max can be seen with the command

cat /proc/sys/fs/file-max

This value is the total for the system, not per process.

# available limit
user@ubuntu:~$ ulimit -n

# To increase the available limit to say 65535
user@ubuntu:~$ sudo vim /etc/sysctl.conf

# add the following line to it
fs.file-max = 65535

# run this to refresh with new config
user@ubuntu:~$ sudo sysctl -p
# edit the following file
user@ubuntu:~$ sudo vim /etc/security/limits.conf

# add following lines to it
* soft     nproc          65535    
* hard     nproc          65535   
* soft     nofile         65535   
* hard     nofile         65535
root soft     nproc          65535    
root hard     nproc          65535   
root soft     nofile         65535   
root hard     nofile         65535

# edit the following file
user@ubuntu:~$ sudo vim /etc/pam.d/common-session
# fedora => /etc/pam.d/login

# add this line to it
session required

# logout and login and try the following command
user@ubuntu:~$ ulimit -n