Can not login after change limits.conf

I am update /etc/security/limits.conf

* soft nofile 10000000
* hard nofile 10000000

I forgot to change /etc/sysctl.conf

fs.file-max = 10000000 
fs.nr_open = 10000000

I can't login through SSH. Include root user.

So how should I login the server(ssh) and fix it.

System: CentOS release 6.3


Solution 1:

The only way I know to gain access back to your machine requires you to be physically near the server.

Then, you reboot the server and when grub menu shows up you hit 'e' on the first line, add in the end of the command the word "single" or just the number 1, then hit enter and then 'b' to boot that line in grub.

Then when the server starts you run:

mount -o remount,rw / 
mount -o remount,rw /proc 

To remount "/" directory as read-write and allow saving files as single user mode starts with read-only filesystem.

Then you fix your /etc/security/limits.conf file and reboot the server.

Solution 2:

have you tried something like below?

ssh user@server 'echo "fs.file-max = 10000000" > /etc/sysctl.conf; echo "fs.nr_open = 10000000" >> /etc/sysctl.conf'

Also it may be problem with spawning bash, so rsync/scp of complete file could do the work.