Advanced Linux Cheat Sheet

This are just random commands that i keep forgetting and i need a place check them out instead of googling every time i need them.

Add your public key to the authorized keys of a remote host
cat ~/.ssh/id_rsa.pub  | ssh remote_host 'cat -  >> ~/.ssh/authorized_keys'


Skip first directory of a tar file
tar -zxvf ~/dokuwiki-5422200921b877a379e34cc4e0fee22a.tgz --strip 1


Check which package provides a file in Red Hat systems
$ yum whatprovides /bin/grep

or

$ rpm -qf /bin/ls


Show list of files on a package
$ rpm -ql glibc-common


List dependecies of a package
$ yum deplist cracklib


List packages that depend on a package
$ repoquery --whatrequires cracklib


Remove package with no dependencies
rpm -e --nodeps cracklib-dicts


Backup using rsync+ssh
rsync -avz -e ssh --progress /home/myuser/  remote.machine:/backups/


Route two networks using iptables
# echo 1 > /proc/sys/net/ipv4/ip_forward
# sysctl -w net.ipv4.conf.all.forwarding=1
# iptables -I FORWARD -i eth0 -o virbr0  -j ACCEPT
# iptables -I FORWARD -i virbr0 -o eth0 -j ACCEPT     


Connect to wifi using NetworkManager cli
$ sudo nmcli -a device  wifi connect ROUTER-SSID password 3662613362 wep-key-type phrase  ifname wlp3s0


Export/Import GPG Keys
$ gpg2 --export -a  <KEY_ID> > gpg_pubkey.asc
$ gpg2 -v --export-secret-keys -a -o gpg_key.key <KEY_ID>
$ gpg2 --import gpg_pubkey.asc 
$ gpg2 --import gpg_key.key