Chris Johnston

Web development and design with a little VFX thrown in for fun
  • Home
  • About Me
  • Contact Me
  • Projects
  • Resume

Securing your Linux box

Published by Chris Johnston on November 9, 2004 11:11 pm under Articles, Linux

Everyone knows that Linux is secure, but this does not mean that your computer is uncrackable. Even though Linux is more secure than Windows, there are still things you can do to prevent your computer from being attacked and to prevent your computer from being compromised. This article is going to list a few things that you can do to help secure your Linux computer against an SSH attack from the outside.

*hosts.allow and hosts.deny*
This is probably your first line of defense. These two files control who can gain access to your computer in the first place. They do this by restricting the people according to their IP address, IP range, or domain name. In order for them to work correctly, you really need to use them both together. Block everyone using the hosts.deny file and then only let those people in that you trust using the hosts.allow file. Check the man pages for both files, but here are two simple examples to show you how the files work. If you wanted to block everyone from accessing your computer except for those on your internal network, this is how the files would be setup:

hosts.deny

ALL: ALL

hosts.allow

ALL: LOCAL, 192.168.0.

You will notice that for the internal network IP, I did not specify an entire address. I left the last digit off. This allows you to specify a block of addresses. In this case, anyone trying to access the computer whose IP address begins with 192.168.0 will be allowed. Basically, this allows anyone on your internal network to gain access (assuming that you network uses 192.168.0).

In addition, you can also specify domains and/or outside IP addresses and IP address ranges. For instance, if the company that you work for has a domain called www.foo.com, then you could specify that in the hosts.allow file. This would allow you to connect from work. Or, if your company only uses IP addresses, then you could put that in as well. Here is what the file could look like:

ALL: LOCAL, 192.168.0.
ALL: .foo.com, 123.456.789.

This establishes where you can connect to your computer from. But what if you don’t want to restrict the entire world from connecting? Then the next best thing is to restrict how they can connect. For this, we secure SSH.

*Securing SSH*
For this, you will need to edit your sshd_config file. This is usually located in /etc/ssh/sshd_config. There are two key areas that you will want to change. The first will look like this:

# Authentication:
#LoginGraceTime 120
#PermitRootLogin no
#StrictModes yes

What you want to do here is to uncomment the PermitRootLogin. This will prevent anyone from logging onto your computer over ssh as root. This means that in order to gain root access, someone will have to first login using a regular user account and then su to root.

The second thing you can do to secure SSH is to which users/groups can login and which can not. To do this, you use four commands – AllowGroups, AllowUsers, DenyGroups, DenyUsers. You use the AllowGroups and AllowUsers to explicitly state which users and which groups can log in through SSH and you use the DenyGroups and DenyUsers to deny all other accounts from logging in. And these you can place at the end of your sshd_config file. An example might look like this:

AllowGroups users foo
AllowUsers foo
DenyGroups root bin postrges mysql nobody apache
DenyUsers root bin postgres mysql nobody apache

And that is all that there is to it. Listed above are two simple tricks to securing a Linux computer. However, they are not guaranteed to make your computer completely cracker proof. There are many more things that you will need to do in order to completely secure your computer against attack (proper firewall, secure all open ports, use secure passwords, etc). But the above is a very good start and should be a part of every linux users toolbox when it comes to securing a computer on the Internet.

No Comment

Comments are closed.

Posting your comment.

  • Search

  • Categories

    • .NET (2)
    • Agile (41)
    • Apple Mac (15)
    • Application Development (124)
    • Articles (4)
    • ColdFusion (2)
    • Demo/Tutorial (3)
    • Eclipse (1)
    • Flash (6)
    • General (567)
    • Git (1)
    • Google (1)
    • Hibernate (4)
    • J2EE (39)
    • Java (111)
    • Java Frameworks (5)
    • Links (1)
    • Linux (33)
    • Miscellanous (2)
    • NetBeans (3)
    • News (10)
    • Open Source (6)
    • Photography (2)
    • Programming (33)
    • Python (1)
    • Ruby (27)
    • Ruby on Rails (14)
    • Ruby on Rails Web Apps (1)
    • Software (14)
    • Spring (4)
    • Teaching (1)
    • TeamDocs (6)
    • Technology (2)
    • Test Driven Development (1)
    • Thoughts (33)
    • ThoughtWorks (8)
    • Tips and Tricks (1)
    • User Experience (1)
    • Web Design (7)
    • Web Development (37)
    • Wicket (1)
  • Archives

    • September 2009 (1)
    • June 2009 (1)
    • May 2009 (1)
    • April 2009 (7)
    • March 2009 (2)
    • February 2009 (6)
    • January 2009 (4)
    • December 2008 (3)
    • October 2008 (1)
    • September 2008 (2)
    • August 2008 (6)
    • July 2008 (4)
    • June 2008 (1)
    • May 2008 (8)
    • April 2008 (7)
    • March 2008 (2)
    • February 2008 (1)
    • January 2008 (5)
    • December 2007 (3)
    • November 2007 (4)
    • October 2007 (5)
    • September 2007 (2)
    • August 2007 (3)
    • July 2007 (6)
    • June 2007 (5)
    • May 2007 (5)
    • April 2007 (5)
    • March 2007 (6)
    • February 2007 (9)
    • January 2007 (16)
    • December 2006 (6)
    • November 2006 (15)
    • October 2006 (17)
    • September 2006 (27)
    • August 2006 (22)
    • July 2006 (14)
    • June 2006 (10)
    • May 2006 (18)
    • April 2006 (3)
    • March 2006 (6)
    • February 2006 (15)
    • January 2006 (7)
    • December 2005 (11)
    • November 2005 (8)
    • October 2005 (18)
    • September 2005 (24)
    • August 2005 (18)
    • July 2005 (21)
    • June 2005 (14)
    • May 2005 (23)
    • April 2005 (18)
    • March 2005 (34)
    • February 2005 (27)
    • January 2005 (27)
    • December 2004 (15)
    • November 2004 (17)
    • October 2004 (20)
    • September 2004 (10)
    • August 2004 (21)
    • July 2004 (9)
    • June 2004 (11)
    • May 2004 (4)
    • April 2004 (15)
    • March 2004 (12)
    • February 2004 (7)
    • January 2004 (17)
    • December 2003 (11)
    • November 2003 (8)
    • October 2003 (12)
    • September 2003 (12)
    • August 2003 (12)
    • July 2003 (23)
    • June 2003 (22)
    • May 2003 (14)
    • April 2003 (9)
    • March 2003 (22)
    • February 2003 (24)
    • January 2003 (32)
    • December 2002 (11)
    • November 2002 (16)
    • October 2002 (10)
    • September 2002 (9)
    • August 2002 (13)
  • Pages

    • About Me
    • Contact Me
    • Projects
    • Resume

Copyright © 2010 Chris Johnston
WordPress Theme based on Light Theme