This topic describes the cause of and solution to the issue that the "could not set limit for 'nofile': Operation not permitted" error message appears when you connect to a Linux Elastic Compute Service (ECS) instance by using SSH.
Problem description
When you connect to a Linux ECS instance by using SSH, the following error message appears:
-bash: fork: retry: Resource temporarily unavailable.
pam_limits(sshd:session): could not sent limit for 'nofile':operation not permitted.
Permission denied.Cause
The nofile value in the resource limit configuration file named /etc/security/limits.conf in the Linux kernel is too large and exceeds the maximum number of files that the kernel can open. As a result, you cannot use SSH to connect to the Linux ECS instance.
Solution
You can modify the /etc/sysctl.conf or /etc/security/limits.conf configuration file based on your business requirements to resolve the preceding issue.
Connect to the Linux ECS instance by using Virtual Network Computing (VNC).
For more information, see Methods for connecting to an ECS instance.
Run the following commands to view the values of the
fs.file-maxandfs.nr_openparameters.Modify the
/etc/sysctl.confconfiguration file.Open the
/etc/sysctl.confconfiguration file.vim /etc/sysctl.confPress the
Ikey to enter Insert mode.Change the values of the
fs.file-maxandfs.nr_openparameters.We recommend that you change the values of the
fs.file-maxandfs.nr_openparameters to a value that is greater than 65536.fs.file-max: The number of files that can be opened by all processes in the kernel.fs.nr_open: The number of files that can be opened by a single process in the kernel.
Notefs.file-max = 655360 fs.nr_open = 655360
Modify the
/etc/security/limits.confconfiguration file.Open the
/etc/security/limits.confconfiguration file.vim /etc/security/limits.confPress the
Ikey to enter Insert mode.Change the values of the
* soft nofileand* hard nofileparameters.For example, change the values of the
* soft nofileand* hard nofileparameters to values that are greater than 65535.* soft nofile 655350 * hard nofile 655350
Restart the ECS instance.
For more information, see Start an instance.
Run the following commands in sequence to check whether the values of the
fs.file-maxandfs.nr_openparameters are changed:cat /proc/sys/fs/file-max cat /proc/sys/fs/nr_open