I'm on EC2 t2.small instance (2GB RAM) and keep getting locked outside the server without the ability to ssh into it.
error message is ssh_exchange_identification: read: Connection reset by peer
Knowing the application, I assume it leaks memory and that SSHD is blcoked due to that.
Is there a way to allow SSH connection to a linux box that has its RAM full?
Can I someone have SSHD reserve enough memory for new connections?
To set the SSH keep alive option on the server: 1 Log in as root 2 Edit the file at /etc/ssh/sshd_config 3 Add this line to the file: ClientAliveInterval 60 4 Save the file 5 Restart sshd on the server More ...
Using nohup command to Keep Running SSH Sessions If you are not that familiar with screen or tmux, you can use nohup and send your long running command to background so that you can continue while the command will keep on executing in background. After that you can safely log out.
Here’s how to temporarily prevent SSH from timing out. Usually what happens is that your connection to the server is reset when you’ve been idle for a while, typically producing the error: Connection reset by peer. To circumvent this, you need to set a Keep Alive option on either the client or the server. Option 1) Server Side Keep Alive
If you spend a lot of time at the command line you may have run into an annoying issue where your session times out after a relatively brief period of inactivity. While this is desirable from a security perspective, it can cause problems when you’re trying to perform a long running operation. Here’s how to temporarily prevent SSH from timing out.
When server runs into out-of-memory, it usually kills several applications which is control by OOM(out of memory) Killer. In your case when your server goes into out-of-memory it kills SSH process to free ram. We can avoid this by disabling OOM killer for ssh Process :
Disabling OOM killer for any process :
echo -17 > /proc/`pidof Process`/oom_adj
Disabling OOM Killer for ssh all process:
pgrep -f "/usr/sbin/sshd" | while read PID; do echo -17 > /proc/$PID/oom_adj; done
To automate this we need to set crontab for 1 min
*/1 * * * * root pgrep -f "/usr/sbin/sshd" | while read PID; do echo -17 > /proc/$PID/oom_adj; done
You can read more about the Linux OOM killer here.
While you can't pre-allocate memory for sshd
, you can set the memory limit for the application in such a way that it can't eat all the memory. See man ulimit
how to do that.
If it's a Java application, try -Xmx
to set the maximum amount of memory which it can allocate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With