Copyright

Creative Commons License

This work is licenced under a Creative Commons Licence.

User login

HOWTO: increase the maximum number of files

Whilst I was aware that "ulimit" was responsible for setting the maximum number of files a user could have open in Linux, I rarely need to alter this value. Today when I needed to increase it for a relatively niche purpose, and I was shocked to realise that I couldn't remember how to do this.

I knew that I could check all my ulimit values using "ulimit -a" (output on default install of ubuntu below) and that I could check how many files specifically using "ulimit -n".

ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 53248
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 53248
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

So, how do I change this? Well, I tried, as root, "ulimit -n 4096" but this only affected the root user seemingly. It appears the correct way is to edit /etc/security/limits.conf and append/edit the following values (where $username is the username of the user you wish to edit the value for):

$username soft nofile 4096
$username hard nofile 4096

Subsequent logins should then have a max number of files open of 4096. I'm writing this down as I know that I have changed it previously, and appeared to have totally forgotten how to do it this time around.