Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am seeing some log enties that look like hacking attempts

Type 1

Dec 26 03:09:01 ... CRON[9271]: pam_unix(cron:session): session closed for user root
Dec 26 03:17:01 ... CRON[9308]: pam_unix(cron:session): session opened for user root by (uid=0)

Type 2

Dec 26 03:27:11 ... sshd[9364]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=60.217.235.5  user=root
Dec 26 03:27:12 ... sshd[9364]: Failed password for root from 60.217.235.5 port 47933 ssh2

What does these mean? They usually come in 5's. I enabled ufw limit ssh. So I think UFW is trottling this. But wonder why are there 2 kinds, 1 authentication failure, 1 session closed.

I suppose I should respond to this by using denyhosts, changing ssh port & disable root login? What else can I do? Last time I used deny hosts, it blocked me too ... Also can I increase the UFW retry time? Like only allow login 1hour later? Perhaps reduce the login attempts to 3?

share|improve this question
1  
The first pair of messages you pasted aren't related to SSH, they indicate a (successful) local sessions opened by cron. –  Mat Dec 26 '11 at 6:09
    
One simple thing you can do is disallow ssh login via root. There is a setting for this. PermitRootLogin no in /etc/ssh/sshd_config. –  Faheem Mitha Dec 28 '11 at 2:26
add comment

3 Answers

up vote 3 down vote accepted

As already mentioned, the first type does not come from any SSH related stuff, its an activity log of your cron deamon and this is not harmful, but usual. The second one might be login attempts from a hacker, and these should be followed. denyhosts might help you, but disabling the possibility for root logins is also a very good idea (in addition to denyhosts, not instead of!)

share|improve this answer
add comment

You can use a method called "port knocking".

Google "iptables port knocking".

To outside world this will look like as you have no ssh server running.

share|improve this answer
1  
Can you describe the basics of the technique a bit more? It's helpful to give the term, but then telling people to google isn't what we're all about. Thanks! –  mattdm Dec 26 '11 at 16:32
    
That's all already described on the internet. I do not think to do copypast is a good idea. You can read more about this, for example, here wiki.archlinux.org/index.php/Port_Knocking –  int Dec 26 '11 at 18:12
1  
I agree, copying and pasting doesn't add value. But a nice summary does. –  mattdm Dec 26 '11 at 18:35
add comment

The messages from CRON record normal activity. These are scheduled tasks (probably executed hourly or daily) that are executed by root.

The messages from SSH indicate that someone tried to log in as root. There are bots that try random addresses and attempt to log in with weak passwords or to exploit security holes. Most people can ignore these attempts, all you need is to observe simple hygiene:

  • Either disable password authentication altogether in /etc/sshd_config (possibly /etc/ssh/sshd_config or some similar location depending on your distribution) by setting PasswordAuthentication No; or make sure that every user on your system has a strong password (not a dictionary word or a simple variation on one).
  • Make sure your ssh server is up-to-date (no known security holes).

You can implement more stringent measures if the attempts are using a significant portion of your bandwidth or CPU or logging space, but beware that restricting SSH could lock you out one day. Changing the port will make you invisible to most bots (you're no longer amongst the lowest hanging fruit), but then you may be unable to log in through some firewalls (if you do want to change the port, and you aren't running an HTTPS server, 443 is good because most firewalls allow HTTPS and can't tell the difference with SSH). Denyhosts will keep the number of attempts down. Port knocking is yet another method, but it's not very useful: you can only log in from a machine that you control that is not behind a stringent firewall, and the benefit is fairly small.

share|improve this answer
add comment

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.