I had the same issue with the error as this and this question (both of which I read and understood), the message being:

$ ulimit -n 20000
ulimit: bad limit: Operation not permitted

I encountered this issue on FreeBSD 8.3 after an upgrade from 7.3 and thought it may have had something to do with the upgrade.

I also had all sorts of issues running the command as root and could only run it as a standard user - which is what I wanted in any case.

The issue is that with FreeBSD the command is limit, not ulimit.

When I ran as a normal user:

%limits -n 20000

I got the exact result I wanted which was to increase the openfile limit from 11095 to 20000, or so I thought.

The output was:

Resource limits (current):
  openfiles               20000

However when I ran the limit command again the limit is shown back at 11095.

How do I change either the hard/soft limit on a FreeBSD 8.3 box?

  • 2
    limit is the command in csh and tcsh. ulimit is the command in other shells. limits will either run a command with modified limits, or give you an appropriate set of commands to eval in your shell to set limits. You probably want eval `limits -e -S -n 20000` – Mark Plotnick Apr 25 '14 at 1:59
  • Thanks for that @MarkPlotnick however when I run # eval limits -e -S -n 20000` ulimit: Command not found.` I get that answer as root, and as a normal user, eval limits -e -S -n 20000` ulimit: bad limit: Operation not permitted` – Deesbek Apr 25 '14 at 2:42
  • Looks like, when you're root using csh, limits is guessing the wrong shell to output commands for. Try running limit directly: # limit desc 20000 . In your normal-user example, limits is working correctly but ulimit is unable to raise the limit higher than the hard limit. You need to raise the hard limit for that normal user first, either by editing config files and logging in as that user again, or by running limit -h desc 20000 as root and then using su to become the user. – Mark Plotnick Apr 25 '14 at 14:48

There is an overall limit set by the sysctl kern.maxfilesperproc.

To change this, edit /etc/sysctl.conf to include something like:


Then do service sysctl restart

You may have to log in again, or reboot, to see the new maximum.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.