Google Plus

9 Best practices to secure your Linux Desktop & Server | Including installation & Configuration

Written by Ayesha .A on . Posted in Linux tutorials

There are a few common security practices that every Linux user should follow. Unfortunately, not everybody is linux-logoaware of these. In this post will show you how to secure your home pc or server to the best of your abilities with the best available opensource tools.

1- Checking your system for random mailers:

Mailers like Form Mail are used by hackers to send out spam emails, relay messages that are security risks for yourself and so on. You can find them using the following command:

find / -name "[Ff]orm[mM]ai*"

CGIeMail is another one that has similar issues.

find / -name "[Cc]giemai*"

Upon finding them, issue the following:

chmod a-rwx /path/to/filename

a-rwx = all types, no read, no write, no execute

2- Check your system using the root kit checker:

Hackers can sometimes install a rootkit on your computer without you even knowing or even set it to run at a specified time through cron. You can check your system with chrootkit. Open up a terminal and execute the following:

cd ~
wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz
tar xvzf chkrootkit.tar.gz
cd chkrootkit-0.44
make sense

Now to run it, just run this:

~/chkrootkit-0.44/chkrootkit

Please do remember to run it on a regular basis.

3- Set up a root login detector and emailer:

This nifty little trick will allow you to be warned if someone actually does manage to login as root on your computer or server.

We need to edit .bash_profile for root. Grab your favorite text editor and add the following line at the end of it:

echo 'ALERT - Root Shell Access on:' `date` `who` | mail -s "Alert: Root Access from `who | awk '{print $6}'`" your@email.com

Replace your@email.com with your own email. Save the file and exit.

4- Set a SSH MOTD:

If your particular machine is a server, this can help.

Grab your favorite text editor and open up /etc/motd

Save your message to the file and exit. An example can be as follows, come up with your own, though.

“This system is restricted to authorized access only. All activities on
this system are recorded and logged. Unauthorized access will be fully
investigated and reported to the appropriate law enforcement agencies.”

5- Secure SSH Logins:

If your server or computer has more than one IP, bind sshd to one of those IPs and don’t use it for anything else. This adds an extra layer of security.

We need to edit /etc/ssh/sshd_config

Scroll down to the section of the file that looks like this:

#Port 22
#Protocol 2, 1
#ListenAddress 0.0.0.0
#ListenAddress ::

Uncomment the Port part and input anything else than port 22. Something above the 40k range is good. Make protocol only 2 instead of 2, 1. I you have more than one IP, change the listen address entry accordingly.

Disable root login through ssh

Find #PermitRootLogin yes and change it to PermitRootLogin no.

Now restart sshd and check out if everything is working fine.

 

6- Disable Telnet:

As root, edit the file /etc/xinetd.d/telnet and change disable = no to disable = yes

Save the file and exit. Restart xinetd through /etc/init.d/xinetd restart

7- Nuke PHP Shells:

Hackers sometimes put these on server for easy access or administration later on. Run the following commands and remove stuff you find suspicious.

locate irc

locate BNC

locate ptlink

locate BitchX

locate guardservices

locate psyBNC

locate eggdrop

locate bnc

locate .rhosts

Be warned that this can sometimes bring up legit files. So be a bit careful.

8- Install Brute Force Detection:

This is an optional step for the truly paranoid ones. It does provide an additional layer of security though.

cd /root/
wget http://www.rfxnetworks.com/downloads/bfd-current.tar.gz
tar -xvzf bfd-current.tar.gz
cd bfd-0.4
./install.sh

We need to edit its config file. Grab your favorite editor and edit /usr/local/bfd/conf.bfd

Find the following and change accordingly ->

Find :
ALERT_USR=”0″
and change it to
ALERT_USR=”1″

Find :
EMAIL_USR=”root”
and change it to
EMAIL_USR=”your@email.com

Save the changes and exit.

Start BFD with the following command:

/usr/local/sbin/bfd –s

With the correct deployment of these methods, we hope that your system is now a bit more secure than it used to be. And as always, keep your OS updated with the latest security patches and updates.

9- Encrypt your data

Last, but is the most important security practice is to encrypt your data, for this check our previous post.                                                                  

Thanks again to Convexity for this post

{module user9-footer}

For questions please refer to our Q/A forum at : http://ask.unixmen.com

  • http://enteryoursiteURL... jim

    the ssh motd wouldn’t be shown unless a user logs in successfully, right?

    so you’d have to make sure:

    Banner /etc/motd

    is set in your sshd_config in order for them to get that warning BEFORE the login

  • http://enteryoursiteURL... john

    This is a terrible article, the "9 best practices" are a complete fabrication. "Best practice"? In whose world? This is laughably bad.

    I have to assume you’ve never actually hardened a system.

    Please see the following, for anyone interested in actually securing a Linux OS:

    http://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf

    Sorry to be so critical, but this is such an important subject I can’t not say this.

  • Bart

    Hope this link works. The other one to the nsa.gov site does not work.

    http://www.nsa.gov/ia/guidance/security_configuration_guides/operating_systems.shtml#linux2

    yep…it’s a long one

  • http://jdpfu.com JohnP

    Fail2ban

    Logwatch

    Don’t allow passwords for ssh, only key-based connections.

    Use the ~/.ssh/config so connecting to non-standard ports and different userids is trivial.

    Actually enable the firewall.

    Setup NTP to keep your system clock correct. Having the correct time is a security issue.

    Disable Javascript for most websites using NoScript.

    Limit any services (disable any that you don’t actually use) like Samba/CIFS to your subnet.

    Lots more at my blog under the "Security" link.

  • http://enteryoursiteURL... jake
  • http://www.xenoactive.org/ Xenoactive

    This article is more about how to detect remnants of a hack rather than hardening a Linux system.

  • Dinos

    There is an extra space or some control character in the link. Use this link (http://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf) and you will get the document …
    [quote=john]This is a terrible article, the "9 best practices" are a complete fabrication. "Best practice"? In whose world? This is laughably bad.

    I have to assume you’ve never actually hardened a system.

    Please see the following, for anyone interested in actually securing a Linux OS:

    http://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf

    Sorry to be so critical, but this is such an important subject I can’t not say this.[/quote]

  • mat

    Critics aside, there’s a couple of lines that could use some corrections enclosed in {}
    1- cd chkrootkit-0.4{9}
    make sense

    Now to run it, just run this:

    ~/chkrootkit-0.4{9}/chkrootkit

    2- tar -xvzf bfd-current.tar.gz
    cd bfd-{1}.4
    {sudo su}
    ./install.sh

    We need to edit its config file. Grab your favorite editor and edit /usr/local/bfd/conf.bfd

    Find the following and change accordingly ->

    Find :
    {EMAIL_ALERTS}="0"
    and change it to
    {EMAIL_ALERTS}="1"

    Find :
    EMAIL_{ADDRESS}="root"
    and change it to
    EMAIL_{ADDRESS}="your@email.com"

    Hope the changes provided above (again, between {}) help those trying to play around with these.

  • Mégamodeste

    Evidement votre système devra être débarassé de tout logiciel propriétaire (pas de gogle, pas de flash, pas de gadget, etc).

    Of course get rid of any gogle, flash, gadget, etc).

  • Hima

    How to install opentaps in ubuntu10.10??
    Plz help me

  • Pingback: 9 Best practices to secure your Linux Desktop & Server | Including … | What is Linux

Like us on Facebook

This week Top Posts

Write for us

Recent Comments

jacky can

|

You can actually unzip your secret archive by leaving out the -t option, instead using:

unzip newPhoto.jpg

DragonFartOutLoud

|

it went to china.

DragonFartOutLoud

|

great review! i’ve been using it as my main OS since Beta 1 release. its been a awesome ride so far :)

jet li

|

i try the method, and i unzip the image contain zip secret, i dont find the file that i was hide, where it go? and how to open it? :s

zinovsky

|

Yes, it is possible using Steganography, we will post another quick howto do that in the next few days

 
IDG Tech Network
Copyright © 2008-2013 Unixmen.com .
Maintained by Anblik .