Security is relative. Will these steps make your server “secure”? It will be more secure than it was before. And more secure than most servers. Your server will not be “low hanging fruit”. Security is an on-going process. It includes settings, practices and procedures. Make it your business to regularly read about security and to understand the concepts and our system. Paranoia is useful with regard to server security.
I’ve tested what is presented here in Ubuntu Server 8.04 (Hardy). If you want to harden your new Ubuntu server, this is a good start.Ubuntu server is well designed, regularly updated and relatively secure. The Ubuntu Security Team manifests an onging effort to keep Ubuntu secure. Regular security updates are available and easy to implement.
- No open ports
- Role-based administration
- No X server
- Security updates
- Kernel and compiler hardening
- Change settings for increased security
- Implement UFW, the uncomplicated firewall
- Use denyhosts to automatically blacklist attackers
- Scan the system for vulnerabilities with Tiger
- Detect attempted intrusions with psad
- Install nmap and scan the system for open ports
- Check the system for rootkits with chkrootkit
- Monitor logs
Change settings for increased security
see also: https://help.ubuntu.com/community/StricterDefaultsSecure shared memory
/dev/shm can be used in an attack against a running service, such as httpd. Modify /etc/fstab to make it more secure.1.sudo vi /etc/fstab1.tmpfs /dev/shm tmpfs defaults,noexec,nosuid 0 0Disable root SSH login
The root account is disabled by default in Ubuntu. If you installed Ubuntu on Slicehost or Linode, root is enabled. In any case, it is a good idea to disable root SSH access. Edit /etc/ssh/sshd_config and set PermitRootLogin to no.1.sudo vi /etc/ssh/sshd_config1.PermitRootLogin noOnly allow admin users to use su
This helps prevent privilege escalation.By default, Ubuntu does not have an admin group. Create an admin group:
1.sudo groupadd admin1.sudo usermod -a -G admin andrew1.sudo dpkg-statoverride --update --add root admin 4750 /bin/su1.ls -lh /bin/su1.-rwsr-x--- 1 root admin 31K 2010-01-26 17:09 /bin/suDo not permit source routing of incoming packets
see also: http://www.cromwell-intl.com/security/security-stack-hardening.html1.sudo sysctl -w net.ipv4.conf.all.accept_source_route=02.sudo sysctl -w net.ipv4.conf.default.accept_source_route=0Don’t allow system users to access an FTP server
This is only needed is ftpd is installed and running. Only if you’ve installed ftpd. However, it is Ok to do this anyway and it will remove a FAIL from the tiger report.SFTP is probably better than FTP, if it is usable for your files transfer needs.
see ftpusers manual: http://manpages.ubuntu.com/manpages/lucid/man5/ftpusers.5.html
Edit /etc/ftpusers:
1.sudo vi /etc/ftpusers01.backup02.bin03.daemon04.games05.gnats06.irc07.libuuid08.list09.lp10.mail11.man12.mysql13.news14.ntp15.postfix16.proxy17.sshd18.sync19.sys20.syslog21.uucp22.www-dataUFW: basic firewall
previous post: Ubuntu UFW Uncomplicated Firewall Examplescommunity documentation: https://help.ubuntu.com/community/UFW
server guide: https://help.ubuntu.com/10.04/serverguide/C/firewall.html
ufw manual: http://manpages.ubuntu.com/manpages/lucid/en/man8/ufw.8.html
project wiki: https://wiki.ubuntu.com/UncomplicatedFirewall
nice article: http://savvyadmin.com/ubuntus-ufw/
UFW (Uncomplicated Firewall) provides an easy to understand interface to control iptables (iptables conteol Netfilter, which is built into the kernel). Will just a few commands, your server can control access. Checking status is also easy.
UFW (uncomplicated firewall) is a simple interface used to configure iptables.
Install and enable Uncomplicated Firewall:
1.sudo aptitude install -y ufw2.sudo ufw enable1.sudo ufw show1.sudo ufw status1.sudo ufw allow ssh2.sudo ufw allow httpSee services running and which names to use:
The practice here is to open only ports that you use – ports that use a service that have a service running. To see a list of services that you have running for which you might want to open ports for:
1.sudo ufw app list1.less /etc/servicesDenyhosts: avoid SSH attacks
project: http://denyhosts.sourceforge.net/Looking at /var/log/auth.log on servers that I manage shows a steady streams of attacks on SSH. I am countering these attacks in a number of ways, starting with denyhosts.
Denyhosts periodically scans /var/log/auth.log for repeated failures to access the system via SSH. It then adds these offenders to /etc/hosts.deny. See the project page for details.
1.sudo aptitude -y install denyhosts1.sudo less /etc/hosts.denyTiger: security system scanner
project: http://www.nongnu.org/tiger/Tiger creates an automated security audit by analyzing files and settings on the system and creating a report listing what has been analyzed and listing warning, alerts and failures.
The tiger command creates a report of potential security problems in /var/log/tiger. The use the tigexp command to look up the resulting codes generated for a detailed explanation and what to do to make the system more secure. The problems tiger considers most serious are marked with FAIL.
Install tiger:
1.sudo aptitude -y install tiger1.sudo tiger1.sudo -i2.less /var/log/tiger/`ls -t1 /var/log/tiger | head -1`3.exit1.tigexp dev002fIgnore these:
1.--FAIL-- [dev002f] /dev/fuse has world permissions2.--FAIL-- [logf005f] Log file /var/log/btmp permission should be 660Detect attempted intrusions with psad
project: http://www.cipherdyne.org/psad/Psad is a collection of lightweight daemons that log attempted intrusions, in particular monitoring iptables.
Installation:
1.sudo aptitude -y install psadTo check current status:
1.sudo psad -SNmap: port scanning
project: http://nmap.org/This allows you to see which ports are open, verifying that UFW/iptables is working correctly.
Installing nmap:
1.sudo aptitude install -y nmap1.nmap -v -sT localhost1.sudo nmap -v -sS localhostChkrootkit: check for rootkit presence
project: http://www.chkrootkit.org/Chkrootkit scans the system for evidence that a rootkit has been installed.
This is a confidence test to be used to test whether your system has been compromised. In a perfect world you would not need this…but in this world, it is good to run periodically.
Installing chkrootkit:
1.sudo aptitude install -y chkrootkit1.sudo chkrootkitLogWatch
Ubuntu community documentation: https://help.ubuntu.com/community/LogwatchThe most detailed and informative logs in the world are useless if no one looks at them. Logwatch winnows the deluge to a succinct report…which you will look at. Even so, familiarize yourself with your system’s logs and review them on a regular basis. A daily logwatch habit would be a good start.
Installation:
1.sudo aptitude -y install logwatch1.sudo logwatch | lessOngoing maintenance
Your server is now more secure. Once a week, perform on-going maintenance.Updating software:
1.sudo aptitude update2.sudo aptitude safe-upgradesee: http://wiki.debian.org/Aptitude
Or, you could set-up automatic security updates, if you cannot do the weekly maintenance. This is not a perfect solution because an administrator is not monitoring what is being updated and testing after updates. see: https://help.ubuntu.com/10.04/serverguide/C/automatic-updates.html
Check for attempted instrusions:
1.sudo psad -S1.sudo -i2.tiger3.grep FAIL /var/log/tiger/`ls -t1 /var/log/tiger | head -1`4.exitUse tigexp to list explanations for FAIL codes:
1.tigexp dev002f1.sudo nmap -v -sS localhost1.sudo chkrootkit1.sudo logwatch | lessvisit: http://www.linuxsecurity.com/
Elsewhere
http://www.itsecurity.com/features/ubuntu-secure-install-resource/http://www.cyberciti.biz/tips/linux-security.html
Facebook










