This repository documents how to limit SSH users’ bandwidth on login using Linux traffic control (tc) and PAM session hooks.
- A Bash script is used to apply a
tctraffic shaping rule when an SSH session is opened. - The same script removes the rule when the session is closed.
- The script is executed by PAM, so it runs automatically for SSH logins.
- Logging is written to
/var/log/bandwidth_limit.log.
- Script path (recommended):
/etc/pam.d/ssh/shaper.sh- Make sure it is executable:
chmod +x /etc/pam.d/ssh/shaper.sh
- Make sure it is executable:
In order for SSH to run the script on session open/close, SSH must be using PAM.
- Edit
/etc/ssh/sshd_configand ensure:UsePAM yes
2.you have to include it under /etc/pam.d/ssh and use @include #path_of_the_script