Linux cheat sheet

December 21, 2014

Introduction

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.

 

Miscellaneous

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

 

rsync
todo

 

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 0.0.0.0/0 -p tcp –dport 80 -j ACCEPT

iptables accept by ip

$ sudo iptables -I INPUT -s 172.28.0.0/255.255.0.0 -j ACCEPT

Iptables stateful firewall

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

 

show system variables

$ $PATH

 

Give sudo

$ usermod -a -G sudo exampleuser

 

ssh-keypair on serverside

$ ssh-keygen //follow steps
$ mv id_rsa.pub .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: yourname@example.com” -A example-attachment receiveremail@example.com

mysql (create database, user and grant privileges)

CREATE DATABASE dbname;

USE dbname;

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

FLUSH PRIVILEGES;

 

References

Eli The Computer Guy tar backup

Linode Securing Your Server

 

Leave a Reply