Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: How can I disable sshd for a certain time?

  1. #1
    Join Date
    Jan 2010
    Location
    China
    Beans
    11
    Distro
    Ubuntu

    Question How can I disable sshd for a certain time?

    Hi ,all ! I have a computer running Ubuntu Server 9.10.I think some one is attacking it: they always try to log in to it via ssh. I think I need to disable ssh log in for a certain time if a person failed for 3 times(only disable that one, other people should be OK).There seems to be no that key words in "man sshd_config" .Does anybody have advice for this issue ? Thank you !

  2. #2
    Join Date
    Dec 2009
    Beans
    Hidden!

    Re: How can I disable sshd for a certain time?

    save the following as/in /etc/network/if-up.d/bfa_protection

    Code:
    #!/bin/bash
    [ "${METHOD}" != loopback ] || exit 0
    /sbin/iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH
    /sbin/iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 3 --rttl --name SSH -j DROP
    Then:
    Code:
    chmod u+x /etc/network/if-up.d/bfa_protection

  3. #3
    Join Date
    Oct 2006
    Beans
    107
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: How can I disable sshd for a certain time?

    Quote Originally Posted by yu xintian View Post
    Hi ,all ! I have a computer running Ubuntu Server 9.10.I think some one is attacking it: they always try to log in to it via ssh. I think I need to disable ssh log in for a certain time if a person failed for 3 times(only disable that one, other people should be OK).There seems to be no that key words in "man sshd_config" .Does anybody have advice for this issue ? Thank you !
    You can also have a look at DenyHosts, which is designed for this exact purpose.

  4. #4
    Join Date
    Feb 2007
    Location
    West Hills CA
    Beans
    10,044
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How can I disable sshd for a certain time?

    fail2ban
    -------------------------------------
    Oooh Shiny: PopularPages

    Unumquodque potest reparantur. Patientia sit virtus.

  5. #5
    Join Date
    Apr 2008
    Location
    Wisconsin
    Beans
    766
    Distro
    Ubuntu

    Re: How can I disable sshd for a certain time?

    You don't need to do that, just install firestarter (it's a graphical front end for your systems firewall)

    Code:
    sudo apt-get install firestarter
    and remove permissions for port 22

    firestarter will also show you any attempts that have been made to access your system that have been denied, so you'll be able to see the IP address in question

  6. #6
    Join Date
    Dec 2007
    Location
    New York
    Beans
    323

    Re: How can I disable sshd for a certain time?

    I use denyhosts, its in the repos and does exactly what you're asking for.

  7. #7
    Join Date
    Feb 2010
    Beans
    7
    Distro
    Xubuntu 9.10 Karmic Koala

    Re: How can I disable sshd for a certain time?

    You really should dissable password logins and just use public key authorization.

    This link will guide you through setting up public key authorization
    http://sial.org/howto/openssh/publickey-auth/

    Then just disable password authentication in /etc/ssh/sshd_config
    Then finally restart the daemon with "sudo /etc/init.d/ssh restart" and enjoy
    Last edited by GolemXIV; February 20th, 2010 at 05:31 AM.

  8. #8
    Join Date
    Jun 2007
    Beans
    271

    Re: How can I disable sshd for a certain time?

    As golem said, I would recommend using an RSA key to login instead of a password. Also, fail2ban works great.

  9. #9
    Join Date
    May 2008
    Beans
    2,526

    Re: How can I disable sshd for a certain time?

    I used this guide when it came to the RSA keys.
    http://help.ubuntu.com/community/SSH/OpenSSH/Keys

    But since this is a server you're talking about and not a home user ssh setup then fail2ban is the way to go, it can blacklist them for a period of time that you set after a # of failed attempts within a time frame that you set.
    Last edited by 2hot6ft2; February 20th, 2010 at 06:07 AM.
    Ultimate Edition Links

  10. #10
    Join Date
    Jan 2010
    Location
    China
    Beans
    11
    Distro
    Ubuntu

    Re: How can I disable sshd for a certain time?

    Well,thank you for your advice! You help me a lot !

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •