Today I Remember - OOM-killer
If you are an experienced Linux user, you have probably encountered the dreaded oom-killer at some point. This is a feature of the kernel that kicks in when the system runs out of memory, killing processes to free up resources.
One common victim of the oom-killer is the sshd daemon, which can be a major problem if you rely on SSH for remote access to your server. But fear not - there is a solution!
By adjusting the oom_adj value for the sshd process, you can prevent it from being targeted by the oom-killer. Here is how:
First, open a terminal and run the following command:
echo -17 > /proc/`cat /var/run/sshd.pid`/oom_adj
This sets the oom_adj value to -17, which tells the kernel to avoid killing the sshd process even if the system is under heavy memory pressure.
You can confirm that the change has taken effect by running:
cat /proc/`cat /var/run/sshd.pid`/oom_adj
This should return a value of -17, indicating that the sshd process is now immune to the oom-killer.
If you want to make this change permanent, you can create a cron job that runs the above command on a regular basis. Simply add the following line to your /etc/cron.d directory:
* * * * * root cat /var/run/sshd.pid &> /dev/null && echo -17 > /proc/`cat /var/run/sshd.pid`/oom_adj
This will run the command every minute, ensuring that sshd is always protected from the oom-killer.