I would like to disable ssh login to my system for particular users say X,and Y on specified time 17.00 to 18.00.
so how to achieve this ?
any help would be appreciated.
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
The answer for this is pam_time
: 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.