I was trying to set up 2000 concurrent ssh connections, but got the error message in server log (i.e. journalctl):

sshd[1356]: error: reexec socketpair: Too many open files

I've set both the soft and hard limit for nofile in /etc/security/limits.conf, and ulimit -n gives me 1 048 000.

Also, Max open files in /proc/<ssh_pid>/limitsis 1 048 000, which is consistent with the value of nofile mentioned above (i.e. the value for ulimit).

When my script for setting up ssh connections was running, I tried lsof | wc -l several times and the values it gave me were around 260 000, which is much less than the open file limit.

So my question is why it complains about "Too many open files" when the actual number of open files is far below the limit?

This question seems similar but I still don't know what to do after reading it: FreeBSD: "Too many open files" but should be able to open another 160,000 files

Any idea is appreciated!

  • Do a quick sanity check of the limit being used by sshd. cat /proc/<pid>/limits – steve Aug 6 '15 at 7:09
  • @steve thanks for the comment, but I think I have mentioned in the main post that I have checked the /proc/<ssh_pid>/limits already and that the Max open files is 1 048 000? – Clara Aug 6 '15 at 7:50
  • Did you change the limits for all users or just root? sshd will fork a process and change user to the one connecting to it. Note that in man socketpair you have both EMFILE and ENFILE, the latter refers to the systemy-wide limits on the number of open file descriptors. What does cat /proc/sys/fs/file-max say ? – Patrick Mevzek Nov 28 '17 at 11:21

Your Answer

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

Browse other questions tagged or ask your own question.