Every weekday, I log into my VPS (Linux) at about the same time (between 8am and 9am) using PuTTY.

Is there a way to prevent or automatically fail all other login attempts at other times?

  • 2
    most people online recommend writing a pair of cron jobs that manipulate IPTables, so that your SSH port is only open between those hours. Jul 1, 2014 at 14:13
  • 4
    bear in mind that if something happens, you won't be able to access it at a different time Jul 1, 2014 at 21:17
  • 1
    Unless you have a specific reason for needing to restrict logins to times, this is a bad idea. A secure password will be plenty if all you're trying to do is secure your machine. A linux exploit will (most likely) bypass the login entirely, which makes this useless. Meanwhile, you will be restricting yourself to specific times.
    – Jon
    Jul 2, 2014 at 4:35
  • 2
    better use fail2ban
    – user84207
    Jul 2, 2014 at 7:03
  • 1
    I agree, fail2ban is essential for public facing SSH. it won't protect against some of the very slow botnet-driven distributed brute-force attacks, but for that kind of adversary, there’s little to be done on the services layer anyway. Jul 2, 2014 at 11:35

1 Answer 1


See this manpage for time.conf

user1 ; * ; Wd0000-2400 | Wk1800-0800

would allow the user user1 evenings on weekdays (wk), and all days on weekends (wd), and deny them the rest of the time.

yours would be something like

* ; * ; Al0800-0900
  • Is the Wk1800-0800 rule correct in your example? If yes - does it mean the same as Wk0000-0800|Wk1800-2400 or Mo1800-2400|WkMo0000-0800|WkMo1800-2400|Sa0000-0800?
    – burtek
    Dec 24, 2014 at 17:08
  • yes, that rule came straight from the manpages, so I'm pretty confident its right. yes it should be equivalent to your compound expression. As for your larger rule, are you trying to say: On monday from 6p-12a, Every weekday except monday 12a-8a, Every weekday except monday from 6p-12a, and saturdays from 12a-8p? The ruleset doesn't make entirely logical sense (why allow monday, and then not allow monday for the same time period). Note, be sure to use spaces around your pipes and semi's. bash can be particular about that. Dec 25, 2014 at 1:44
  • Seems that you also have to edit the files in /etc/pam.d/. See the answer on ask.fedoraproject.org/en/question/7260/…
    – erik
    May 1, 2017 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.