Skip to content

Commit

Permalink
Limit cpu usage
Browse files Browse the repository at this point in the history
  • Loading branch information
maniackcrudelis committed Oct 13, 2017
1 parent 9c9576a commit 4853b26
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
13 changes: 13 additions & 0 deletions chroot_manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ add_user () {
exit 1
fi

#=================================================
# SET LOWER PRIORITY
#=================================================

ssh_chroot_set_priority $user_name

#=================================================
# ADD A PASSWORD FOR THIS USER
#=================================================
Expand Down Expand Up @@ -459,6 +465,13 @@ remove_user () {

bold_echo "Delete the user $user_name."
sudo userdel $user_name

#=================================================
# REMOVE PRIORITY
#=================================================

ssh_chroot_del_priority $user_name

done
}

Expand Down
15 changes: 14 additions & 1 deletion ssh_chroot/ssh_chroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ ssh_chroot_standard_binaries () {
ssh_chroot_copy_binary /usr/lib/openssh/sftp-server "$chroot_dir"
}


# Set permissions
ssh_chroot_set_permissions () {
local chroot_dir="$1"
Expand All @@ -77,3 +76,17 @@ ssh_chroot_add_chroot_config () {
# Reload ssh service
sudo systemctl reload ssh
}

# Set lower priority
ssh_chroot_set_priority () {
local user="$1"
# Set a priority at 10 for this user.
# That means, each process started by this user will be less prioritize than all process with a 'nice' under 10.
echo "${user} hard priority 10" | sudo tee /etc/security/limits.d/${user}.conf > /dev/null
}

# Remove priority
ssh_chroot_del_priority () {
local user="$1"
sudo rm -f /etc/security/limits.d/${user}.conf
}

0 comments on commit 4853b26

Please sign in to comment.