Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
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. –  Frank Thomas Jul 1 at 14:13
4  
bear in mind that if something happens, you won't be able to access it at a different time –  Bartlomiej Lewandowski Jul 1 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. –  Chipperyman Jul 2 at 4:35
2  
better use fail2ban –  user84207 Jul 2 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. –  Frank Thomas Jul 2 at 11:35

1 Answer 1

up vote 21 down vote accepted

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
share|improve this answer
    
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 2 days ago
    
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. –  Frank Thomas yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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