Disable ssh login on specified time for particular users

The answer for this is pam_time[1]

[1]: http://www.linux-pam.org/Linux-PAM-html/sag-pam_time.html "pam_time". As always, be careful editing pam and back up your config.


Here's an idea:

In sshd_config add the following line:

AllowUsers USER1 USER3 USER3 USER4

This list should be all users you want to be allowed to ssh to the system. After the list is present restart the sshd service. Then add the following lines to roots crontab:

0 17 * * * /usr/bin/sed -i 's/^AllowUsers.*$/AllowUsers USER1 USER2/' && /sbin/service sshd restart
0 18 * * * /usr/bin/sed -i 's/^AllowUsers.*$/AllowUsers USER1 USER2 USER3 USER4/' && /sbin/service sshd restart

That is written for my centos 6 server, but change paths in your crontab as appropriate as well as the sshd restart command. And of course, replace the user lists with the lists you want at each time.