Since everyone seemed to enjoy my first round of tips and tricks to securing a linux system, I figured I would throw together a few more. Enjoy.
- There are files that get changed very infrequently. For instance, if your system won’t have any users added anytime soon then it may be sensible to chattr immutably the /etc/password and /etc/shadow files. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.
chattr +i /etc/passwd /etc/shadow
- Password protect your linux install with LILO. Edit your /etc/lilo.conf. At the end of each linux image that you want to secure, put the lines:
password = MySecurePassword
Ensure you rereun /sbin/lilo so the changes take effect.
- Users who have sudoer (sudo) accounts setup can have the account setup to change to root without a password. To check this, as root use the following command:
grep NOPASSWD /etc/sudoers
If there is an entry in the sudoers file, it will look like this:eric ALL=NOPASSWD:ALL
To get rid of this, type visudo and remove the line in that file.
- Use sudo to execute commands as root as a replacement for su. In the /etc/sudoers file, add the following lines by using the visudo command:
Cmnd_Alias LPCMDS = /usr/sbin/lpc, /usr/bin/lprm
Now the user ‘eric’ can sudo and use the lpc and lprm commands without having any other root level access.
- Turn off PasswordAuthentication and PermitEmptyPasswords in the SSH configuaration file /etc/ssh/sshd_config. This will ensure that users cannot set empty passwords or login without SSH keys.
- Instead of using “xhost +” to open up access to the X server, be more specific. Use the server name that you are allowing control to:
Once you are done using it, remember to disallow access to the X server from that host:xhost -storm:0.0
- To find out the .Xauthority magic cookie looks like and to send it (authorization information) to the remote host, use the following command:
xauth extract - $DISPLAY | ssh storm xauth merge -
Now the user who ran this command on the original host can now run xcilents on storm. xauth needs to be present on both hosts.
- To turn on spoof protection, run a simple bash script:
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do echo 1 > $i done;
Be careful to remember that it drops packets more or less ‘invisibly’.
- A SYN-flood attack has the ability to bring the network aspect of your linux box to a snail like crawl. TCP_SYNCookies protection attempts to stop this from taking a heavy toll on the machine. To enable cp_syncookies
protection, use the following command:echo 1 > /proc/sys/net/ipv4/tcp_syncookies
- When possible use secure connection methods as opposed to insecure methods. Unless you are required to use telnet, substitute ssh (Secure SHell) in for rsh or telnet. Instead of POP3 or IMAP use SPOP3 or SIMAP (IMAPS). Both SIMAP and SPOP3 are just versions of IMAP and POP3 running over an SSL (Secure Socket Layer) tunnel.