How to increase ulimit on Amazon EC2 instance?

dmodulus picture dmodulus · Jul 5, 2012 · Viewed 46.3k times · Source

After SSH'ing into an EC2 instance running the Amazon Linux AMI, I tried:

ulimit -n 20000

...and got the following error:

-bash: ulimit: open files: cannot modify limit: Operation not permitted

However, the shell allows me to decrease this number, for the current session only.

Is there anyway to increase the ulimit on an EC2 instance (permanently)?

Answer

Viccari picture Viccari · Jul 5, 2012

In fact, changing values through the ulimit command only applies to the current shell session. If you want to permanently set a new limit, you must edit the /etc/security/limits.conf file and set your hard and soft limits. Here's an example:

# <domain> <type> <item>  <value>
    *       soft  nofile  20000
    *       hard  nofile  20000

Save the file, log-out, log-in again and test the configuration through the ulimit -n command. Hope it helps.

P.S. 1: Keep the following in mind:

  • Soft limit: value that the kernel enforces for the corresponding resource.
  • Hard limit: works as a ceiling for the soft limit.

P.S. 2: Additional files in /etc/security/limits.d/ might affect what is configured in limits.conf.