I have a normal Linux user that is:
- only allowed to login via ssh to execute a single command and nothing else
- may never login more the once at a single time
The first restriction is implemented using the command option in the user's authorized_keys file, and works without issue.
The second restriction is implemented using PAM to enforce /etc/security/limits.conf. This part doesn't seem to work at all when I use it in conjunction with the previous restriction, but works otherwise. That is, If I limit ssh logins to a single command, I can log in concurrently as many times as I want. If I do not use the command option, I am not allowed to login more than once at a given time. (login is rejected with the usual error: Too many logins for user 'X'.)
Why is PAM failing to restrict logins when the command option is used in authorized_keys and what can I do to enforce the two aforementioned restrictions as the same time?
sshd is configured to use pam (UsePAM yes).
Addendum: Upon further investigation, it appears that the maxlogins restriction is in fact being respected inevaluated for all casesssh connections (both with the command option specified and without). However, because login/pty sessions are the only type of sessions being counted against the limitmaxlogins, an unlimitedany number of parallel non-interactive sessions can be startedopened as long as the number of interactive sessions isremains bellow maxlogins.
I can see two ways I can tackle this:
- have sshd itself enforce the single connection per user restriction
- find a way to get linux to count non-interactive shells against
maxlogins
I've skimed through the manual pages for both sshd (8) and sshd_config(8) but was unable to find anything relevant. I can force a tty client side (e.g. ssh -tt) but that would leave restriction enforcement in the hands of the clients.