LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-04-2017, 10:08 AM   #1
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Rep: Reputation: 11
Post CentOS release 6.6 and limit SSH by IP.


Hello.
I like to limit SSH connection to my server that use "CentOS release 6.6 (Final)". I Google it and found two ways: 1- use "hosts.allow" file 2- use "sshd_config".
Which one is better and more easy?

Thank you.
 
Old 02-04-2017, 10:13 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,333
Blog Entries: 3

Rep: Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729
The latter. tcpd aka tcpwrappers support is discontinued in modern versions of OpenSSH server. You can do the same filtering with iptables instead. However, to keep everything in one place, you can modify sshd_config to accept or block connections from specific IPs. You might even put it inside a Match block. See the manual page for sshd_config for the authoritative specifics.
 
Old 02-04-2017, 06:37 PM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
What why and how of tcpwrappers
by yours truly. 6.6 is eligible.
 
Old 02-07-2017, 08:24 AM   #4
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
my personal preference is to use ipsets with iptables, works well on CentOS 6, but there have been issues with the ipset package in RHEL/CentOS 7.

With ipsets, instead of having to set-up a rule per ip, you can set rules per ipset and then add ips to the ruleset. For example you could do the following to get two groups for admins and developers with everything else blocked.

ipset -N admins iphash
ipset -A admins 10.0.0.10
ipset -A admins 10.0.1.10

ipset -N developers iphash
ipset -A developers 10.1.0.15
ipset -A developers 172.16.23.72

iptables -I INPUT 3 -m conntrack --ctstate ESTABLISHED -j ACCEPT
iptables -I INPUT 4 -m set --match-set admins src -j ACCEPT -m comment --comment "Admins ipset group can connect all"
iptables -I INPUT 5 -p tcp -m conntrack --ctstate NEW --dport 22 -m set --match-set developers src -m limit --limit 12/hour --limit-burst 5 -m comment --comment "5 login attempts every 5 minutes" -j ACCEPT
iptables -I INPUT 6 -j DROP

of course to get to this level you would have to learn iptables and ipset but it gives you very explicit control over what you allow and do not allow to connect. To be fair the limit module still leaves me a tiny bit confused.

Last edited by r3sistance; 02-07-2017 at 08:28 AM.
 
Old 02-07-2017, 10:58 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,483

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
I'd be tempted to do it at iptables level as it's closer up the chain. That way you can block/reject/drop the traffic before sshd even has the connection to consider.

Then add layers, the more layers the better.

For example it's possible within .ssh/authorized_keys specify that a key is only valid from a specific IP address.
 
Old 02-07-2017, 11:54 AM   #6
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by TenTenths View Post
For example it's possible within .ssh/authorized_keys specify that a key is only valid from a specific IP address.
oh yes! Good point, you can also use DenyUsers and AllowUsers within the SSH configuration to lock down the users. My test box is down at the moment and don't have accessibility to my work test boxes from home but I would usually do something like...

printf "DenyUsers " >> /tmp/denies
# awk -F":" '{print $1}' | tr '\n' ' ' >> /tmp/denies
EDITOR /tmp/denies
-- manually move users you do want to allow, to next line with an AllowUsers
cat /tmp/denies >> /etc/ssh/sshd_config
rm /tmp/denies

restart ssh and test. This way you further fine tune down the security.
 
Old 02-07-2017, 12:02 PM   #7
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,483

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
Quote:
Originally Posted by r3sistance View Post
oh yes! Good point, you can also use DenyUsers and AllowUsers within the SSH configuration to lock down the users. My test box is down at the moment and don't have accessibility to my work test boxes from home but I would usually do something like...

printf "DenyUsers " >> /tmp/denies
# awk -F":" '{print $1}' | tr '\n' ' ' >> /tmp/denies
EDITOR /tmp/denies
-- manually move users you do want to allow, to next line with an AllowUsers
cat /tmp/denies >> /etc/ssh/sshd_config
rm /tmp/denies

restart ssh and test. This way you further fine tune down the security.
Nooooooo......

Create a group "sshusers", use AllowGroups sshusers in your sshd config and then just add sshusers as a secondary group to the users allowed access.
 
1 members found this post helpful.
Old 02-07-2017, 05:07 PM   #8
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by TenTenths View Post
Nooooooo......

Create a group "sshusers", use AllowGroups sshusers in your sshd config and then just add sshusers as a secondary group to the users allowed access.
Fair enough, either way an extra layer of protection to lock down users. I just work with people who would probably get lost if we did it by group unfortunately, more so the junior technical engineers. Tho where I work we also lock things down on hardware or virtual firewall devices too, depending on the customer set-up, even more layers.

Last edited by r3sistance; 02-07-2017 at 05:09 PM.
 
Old 02-07-2017, 10:35 PM   #9
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,333
Blog Entries: 3

Rep: Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729
Quote:
Originally Posted by r3sistance View Post
I just work with people who would probably get lost if we did it by group unfortunately, more so the junior technical engineers.
Sad and strange to hear. Assigning permissions at group level has been established best practice for decades, for what should be obvious reasons. If they can't handle groups, they should not have accounts until they prove themselves capable at remedial training or their replacements can be hired and the old accounts removed instead. This isn't about "security", this is about basic concepts needed to operate the machines they have gotten into. A metal shop makes sure anyone on the floor is both qualified to operate the equipment and follow best practices. This is not much different, just digital.
 
Old 02-08-2017, 06:15 PM   #10
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by Turbocapitalist View Post
Sad and strange to hear. Assigning permissions at group level has been established best practice for decades, for what should be obvious reasons. If they can't handle groups, they should not have accounts until they prove themselves capable at remedial training or their replacements can be hired and the old accounts removed instead. This isn't about "security", this is about basic concepts needed to operate the machines they have gotten into. A metal shop makes sure anyone on the floor is both qualified to operate the equipment and follow best practices. This is not much different, just digital.
Tell me about it, I unfortunately am not responsible for recruiting. Management don't value engineering skills highly and look to always do what is cheapest rather than what is best meaning we get people who many have never had a real IT job before, let alone experience with Linux.

Well the team I am in, we are constantly complaining about many MANY issues. I couldn't really respond to this earlier while I was at work for obvious reasons but honestly every company has issues and if not for our sys admin teams (of which I am in one) the company would have failed a long time ago... anyways not gunna hi-jack this thread too far away. I am instead looking at other jobs.

Sorry apologies about doing things in a bit of a too simplistic way instead of a more functionally correct and secure method, the mindset is a bit off from where I'd like it to be sometimes.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Upgrade CentOS release 5.9 (Final) to CentOS 6.x yogesh_attarde Linux - Server 3 06-07-2013 01:42 AM
Problem with <Limit GET> in httpd.conf on RHEL AS release 4 ccondon23 Linux - Server 2 05-22-2013 12:12 PM
LXer: CentOS-announce Release for CentOS-6.4 i386 and x86_64 LXer Syndicated Linux News 0 03-09-2013 03:50 PM
LXer: CentOS-announce Release for CentOS-5.6 i386 and x86_64 LXer Syndicated Linux News 0 04-09-2011 05:00 AM
how to limit ssh by user and ip cizzi Linux - Security 6 02-15-2008 03:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 07:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration