Linux cheat sheet


Some things are just hard to remember. Nasty moment comes when you have to do something but you just do not remember the right order. These are my weak points. All tested on Ubuntu 14.04 LTS.



tar: create – full backup of /, dont tar /mnt

$ sudo tar -cvpzf backup.tar.gz –exclude=/mnt /

tar: extract – backup extracted to /recover folder

$ sudo tar -xvpz backup.tar.gz -C /recover


Edit crontabs

$ crontab -e




grep: find out how to enable php scripts in user directories with apache

$ sudo grep -r ‘user directories’ /etc/apache2/*

Iptables stuff

iptables accept or drop all

$ sudo iptables -P INPUT ACCEPT // DROP

iptables list rules fast

$ sudo iptables -L -n

iptables format rules

$ sudo iptables -F

iptables accept by port

$ sudo iptables -I INPUT -s -p tcp –dport 80 -j ACCEPT

iptables accept by ip

$ sudo iptables -I INPUT -s -j ACCEPT

Iptables stateful firewall

$ sudo iptables -I INPUT -m conntrack –ctstate ESTABLISHED,RELATED -j ACCEPT


show system variables



Give sudo

$ usermod -a -G sudo exampleuser


ssh-keypair on serverside

$ ssh-keygen //follow steps
$ mv .ssh/authorized_keys
$ chown -R example_user:example_user .ssh
$ chmod 700 .ssh chmod 600 .ssh/authorized_keys


Puppet test gatalog on node do not operate

$ sudo puppet agent – -test – -noop


perl: warning: Please check that your locale settings FIX

$ export LC_ALL="en_US.UTF-8"

Send email from shell

$ echo ‘message’ | mail -s “subject” -a “From:” -A example-attachment

mysql (create database, user and grant privileges)


USE dbname;

GRANT ALL ON dbname.* TO ‘dbuser’@’localhost’ IDENTIFIED BY ‘password’;




Eli The Computer Guy tar backup

Linode Securing Your Server


Leave a Reply