Skip to content

Instantly share code, notes, and snippets.

@aliostad
Last active October 20, 2023 09:28
Show Gist options
  • Save aliostad/3a2245915dee09454f37c760d51522fd to your computer and use it in GitHub Desktop.
Save aliostad/3a2245915dee09454f37c760d51522fd to your computer and use it in GitHub Desktop.
BASH script for increasing file descriptors on linux
MAXFILE=65536
CURRENT_MAXFILE=$(ulimit -n)
function update_sysctl(){
UPDT="fs.file-max = $MAXFILE"
if ! grep "$UPDT" /etc/sysctl.conf; then
echo "$UPDT" >> /etc/sysctl.conf
fi
}
function update_limitsconf(){
UPDT="* soft nproc $MAXFILE"
if ! grep "$UPDT" /etc/security/limits.conf; then
echo "* soft nproc $MAXFILE" >> /etc/security/limits.conf
echo "* hard nproc $MAXFILE" >> /etc/security/limits.conf
echo "* soft nofile $MAXFILE" >> /etc/security/limits.conf
echo "* hard nofile $MAXFILE" >> /etc/security/limits.conf
echo "root soft nofile $MAXFILE" >> /etc/security/limits.conf
echo "root hard nofile $MAXFILE" >> /etc/security/limits.conf
fi
}
function update_session_perm(){
UPDT="session required pam_limits.so"
if ! grep "$UPDT" /etc/pam.d/common-session; then
echo "$UPDT" >> /etc/pam.d/common-session
echo "$UPDT" >> /etc/pam.d/common-session-noninteractive
fi
}
if [ $CURRENT_MAXFILE != $MAXFILE ]; then
update_sysctl
update_limitsconf
update_session_perm
# reboot ==> MAKE SURE YOU REBOOT!!
fi
@aliostad
Copy link
Author

aliostad commented May 5, 2017

Make sure you reboot

@BibbyChung
Copy link

This code has an extra space. Please check again.
image

@aliostad
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment