Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue Oct 19, 2004 7:13 am 
Offline
Senior Member

Joined: Sat Aug 30, 2003 6:35 am
Posts: 57
Hi, I was wondering if anyone could suggest ways for me to remove root's ability to attempt to login via sshd on a linode running debian stable.

What I want is, anyone entering the username 'root' to sshd should simply be dropped, without being given the chance to enter a password.

I've tried setting PasswordAuthentication to no in sshd_config,
but that prevents all my users logging in that way too, which
is not what I want.

I've also tried using PermitRootLogin without-password,
but that doesn't seem to work as the sshd ignores the option.
I've run sshd in -dep mode and a ssh client in -vv mode, but it
seems that sshd is just totally ignoring the options I set in the config.

I've got root logins limited to the console anway........ but I don't
even want root to be given the CHANCE to login....... because all
the annoying dictionary crack scripts keep trying a ton of passwords
on my sshd, and it fills my logs.

Anyone have any suggestions for me as to what to do, or any
reasons why sshd might be ignoring my PermitRootLogin without-password in sshd_config?

Any help would be appreciated :)


Last edited by Ashen on Sun Apr 08, 2012 9:20 pm, edited 2 times in total.

Top
   
PostPosted: Tue Oct 19, 2004 10:00 am 
Offline
Senior Member
User avatar

Joined: Sat Oct 16, 2004 11:13 am
Posts: 176
Ashen wrote:
What I want is, anyone entering the username 'root' to sshd should simply be dropped, without being given the chance to enter a password.


I don't believe thats possible under SSH - you can have SSH not accepting the password and not "logging in" (even if the password is correct) - but not that.

Quote:
because all
the annoying dictionary crack scripts keep trying a ton of passwords
on my sshd, and it fills my logs.


Make SSH listen to a different port, so you won't get as many dictionary-attacks.


Top
   
 Post subject: RSA Key Authentication
PostPosted: Tue Oct 19, 2004 11:42 am 
Offline
Senior Member
User avatar

Joined: Fri Aug 15, 2003 2:15 pm
Posts: 111
Website: http://fubegra.net/
If you use only RSA keys, and disallow password authentication, sshd should simply drop the connection if a key isn't presented.

_________________
Bus error (passengers dumped)


Top
   
 Post subject:
PostPosted: Tue Oct 19, 2004 2:53 pm 
Offline
Senior Member

Joined: Sat Aug 30, 2003 6:35 am
Posts: 57
rjp wrote:
If you use only RSA keys, and disallow password authentication, sshd should simply drop the connection if a key isn't presented.


ashen wrote:
I've tried setting PasswordAuthentication to no in sshd_config,
but that prevents all my users logging in that way too, which
is not what I want.


saman007uk wrote:
I don't believe thats possible under SSH - you can have SSH not accepting the password and not "logging in" (even if the password is correct) - but not that.

:-( - oh well, at least I know now why I couldn't find a way to get it to do that.
saman007uk wrote:
Make SSH listen to a different port, so you won't get as many dictionary-attacks.

Good idea...... I might try that if the dictionary attacks keep annoying me.
Thanks :)


Last edited by Ashen on Sun Apr 08, 2012 9:17 pm, edited 1 time in total.

Top
   
 Post subject:
PostPosted: Tue Oct 19, 2004 2:55 pm 
Offline
Senior Newbie

Joined: Wed Sep 22, 2004 11:53 pm
Posts: 17
This isn't quite what you wanted to do, but when I also noticed all the bad ssh login attempts in my logs I modified my iptables setup to drop excessive ssh connection requests. The relevant section from my firewall script is:

# ssh server
iptables -N ssh-drop
iptables -A ssh-drop $LogLimit -j LOG $LogLevel --log-prefix "FIREWALL:SSH-DROPPED "
iptables -A ssh-drop -j DROP
iptables -A INPUT -p TCP --dport 22 --syn -m recent --name ssh --update --seconds 60 --hitcount 5 -j ssh-drop
iptables -A INPUT -p TCP --dport 22 --syn -m recent --name ssh --set
# log incoming ssh connection requests
iptables -A INPUT -p TCP --dport 22 --syn $LogLimit -j LOG $LogLevel --log-prefix "FIREWALL:SSH-CONNECT "
iptables -A INPUT -p TCP --dport 22 --syn -j ACCEPT
# enable incoming ssh after connected
iptables -A INPUT -p TCP --dport 22 -m state --state ESTABLISHED -j ACCEPT

While I wouldn't call myself an iptables or firewall expert by any means, I've tested it and it seems to do what I expect it should, which is drop all ssh connection requests from any IP that does more than five such requests within 60 seconds until that IP does no such requests for at least 60 seconds. The logging stuff is, of course, optional, and you probably don't want it if your main complaint is the requests filling up your logs. My mail goal was to try to ensure that, however unlikely even without this, no kiddie's script got lucky and hit on a valid password.

HTH


Top
   
 Post subject:
PostPosted: Wed Oct 27, 2004 6:52 pm 
Offline
Senior Member

Joined: Sat Aug 30, 2003 6:35 am
Posts: 57
Thank you :)

I have a firewall right now, which has rules I've built up for a while (default DROP on inbound ports, ALLOW a few server ports, ALLOW a few portsentry ports, else return to default DROP rule)...... but did not think of using iptables to combat this problem.

I will try this method, and see if it works :)


Last edited by Ashen on Sun Apr 08, 2012 9:16 pm, edited 1 time in total.

Top
   
 Post subject:
PostPosted: Sat Nov 20, 2004 7:27 pm 
Offline
Senior Member

Joined: Sat Aug 30, 2003 6:35 am
Posts: 57
Here's my updated ruleset, that's slightly improved (aka the limited logging works on my system and it's commented):

# <Log dropped connections?>
# A (uncomment this section INSTEAD of section B below to enable logging of connections to sshd dropped due to rate limit)
$IPT -N ssh-drop
$IPT -A ssh-drop -m limit --limit 2/minute -j LOG --log-prefix "FIREWALL:SSH-DROPPED "
$IPT -A ssh-drop -j REJECT
# uncomment the first line below if you have a multihomed host, the second one if you don't, or you want to protect all ips.
#$IPT -A tcp_inbound -p TCP -d your_ip_here! --dport 22 --syn -m recent --name ssh --update --seconds 10 --hitcount 3 -j ssh-drop
#$IPT -A tcp_inbound -p TCP --dport 22 --syn -m recent --name ssh --update --seconds 60 --hitcount 5 -j ssh-drop


# B (uncomment this section INSTEAD OF section A above to just drop them without logging anything)
#$IPT -A tcp_inbound -p TCP --dport 22 --syn -m recent --name ssh --update --seconds 60 --hitcount 5 -j DROP

# Leave this one line uncommented no matter which you use above
$IPT -A tcp_inbound -p TCP --dport 22 --syn -m recent --name ssh --set


Top
   
 Post subject:
PostPosted: Sat Apr 30, 2005 7:00 pm 
Offline
Senior Newbie
User avatar

Joined: Thu Feb 03, 2005 10:26 pm
Posts: 18
Good thread on the Gentoo boards:

http://forums.gentoo.org/viewtopic-t-210585-postdays-0-postorder-asc-highlight-ssh+logins-start-0.html

It's focused on the same topic.

-austin


Top
   
 Post subject:
PostPosted: Sat Apr 30, 2005 8:41 pm 
Offline
Senior Member

Joined: Sat Jun 05, 2004 12:49 am
Posts: 333
http://blog.andrew.net.au/2005/02/17


Top
   
 Post subject:
PostPosted: Sat Apr 30, 2005 11:02 pm 
Offline
Senior Member

Joined: Sat Dec 13, 2003 12:39 pm
Posts: 98
As far as blocking just root password logins, have you looked at the SSH PAM settings?

It should be possible to block only root there, it's worth a look. Should be in /etc/pam.d/ssh.

I know it's possible there. You can set up PAM to for example use LDAP for SSH authentication, and if you don't list root in the LDAP dir, then SSH using root would be impossible. LDAP is just an example I know, something simpler should work for you. Check out the /etc/pam.d/login, mine says something about blocking root in the comments.


Top
   
PostPosted: Mon May 02, 2005 9:01 am 
Offline
Senior Member

Joined: Wed Oct 20, 2004 8:55 am
Posts: 120
Ashen wrote:
Hi, I was wondering if anyone could suggest ways for me to remove root's ability to attempt to login via sshd on a linode running debian stable.

You could try removing vc/1 to vc/11 in /etc/securetty

On my home box I had to add ttyp0 to this file to log in over the network as root using ssh. I'm assuming that vc/1 - vc/11 are the same thing in the virtual world of Linode. (Caker / Anyone ?)

Quote:
From my home /etc/securetty
# /etc/securetty: list of terminals on which root is allowed to login.
# See securetty(5) and login(1).
#
# Include ttyp0, ttyp1, etc to allow telnet access. *NOT RECOMMENDED*


Edit:
I ran up a quick Debian test system and gave this a go. I removed everything from /etc/securetty and I could still login as root. So I guess it doesn't work the same under UML.


Top
   
 Post subject:
PostPosted: Wed May 04, 2005 4:03 am 
Offline
Senior Member

Joined: Sun Dec 19, 2004 6:46 pm
Posts: 58
Just modify the sshd config file to disable root logins. There is a setting precisely for this purpose:

PermitRootLogin

For more info, type:

man sshd_config


Top
   
PostPosted: Wed May 04, 2005 4:09 am 
Offline
Linode Staff
User avatar

Joined: Tue Apr 15, 2003 6:24 pm
Posts: 3090
Website: http://www.linode.com/
Location: Galloway, NJ
kangaby wrote:
You could try removing vc/1 to vc/11 in /etc/securetty

On my home box I had to add ttyp0 to this file to log in over the network as root using ssh. I'm assuming that vc/1 - vc/11 are the same thing in the virtual world of Linode. (Caker / Anyone ?)

Edit:
I ran up a quick Debian test system and gave this a go. I removed everything from /etc/securetty and I could still login as root. So I guess it doesn't work the same under UML.


/etc/securetty lists which terminals root can login to. Terminals == consoles, not sshd. So, removing tty0 from securetty will prevent you from logging in as root through Lish.

The correct course of action is to disable PermitRootLogin in your sshd_config file.

-Chris


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group