Question: Debian Lenny. For every user, including root:

```
# cat /proc/sys/fs/file-max
262144

# sysctl fs.file-max
fs.file-max = 262144

# ulimit -Hn
1024

# ulimit -Sn
1024

```

File `/etc/security/limits.conf` has no uncommented lines.

Where does it get that 1024?

Answer: 
The [`fs.file-max` sysctl](http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/sysctl/fs.txt;h=88fd7f5c8dcd61307171b3af852541d06a984380;hb=HEAD#87) shows how many file handles can be allocated *system-wide*, while `ulimit` resource limits are per-process (or per-UID). The former is described in [`Documentation/sysctl/fs.txt:90`](http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/sysctl/fs.txt;h=88fd7f5c8dcd61307171b3af852541d06a984380;hb=HEAD#87):

```

file-max & file-nr:

The value in file-max denotes the maximum number of file-
handles that the Linux kernel will allocate. When you get lots
of error messages about running out of file handles, you might
want to increase this limit.

```

The 1024 files rlimit is not explicitly set anywhere; it's hardcoded into the kernel as the default value for pid 1, at [`include/asm-generic/resource.h:81`](http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/asm-generic/resource.h;h=61fa862fe08d61fb326bd66c20e31c567e3fb6f8;hb=HEAD#l68):

```

/*
 * boot-time rlimit defaults for the init task:
 */
#define INIT_RLIMITS                                                    \
{                                                                       \
        ...
        [RLIMIT_NOFILE]         = {   INR_OPEN_CUR,   INR_OPEN_MAX },   \
        ...
}

```

which references `INR_OPEN_CUR` and `INR_OPEN_MAX` from [`include/linux/fs.h:26`](http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/fs.h;h=178cdb4f1d4afe81a66e631872de4b587e95d1c4;hb=HEAD#l26):

```

#define INR_OPEN_CUR 1024       /* Initial setting for nfile rlimits */
#define INR_OPEN_MAX 4096       /* Hard limit for nfile rlimits */

```

Other processes simply inherit the limit from `init` (or whatever is pid 1).

Why does `/proc/1/limits` on Debian report 1024 as both soft *and hard* nfile limit? I don't know: neither the sysvinit sources nor Debian kernel patches change it. It could be the initramfs scripts, maybe. (I run Arch, which has the 1024/4096 default.)
For the question @grawity brought up, this kernel commit can explain:

```

commit 0ac1ee0bfec2a4ad118f907ce586d0dfd8db7641
Author: Tim Gardner 
Date:   Tue May 24 17:13:05 2011 -0700

    ulimit: raise default hard ulimit on number of files to 4096

```

At lease in RHEL5.4 it's 1024/1024, and in RHEL6.2 it's 1024/4096.