Skip to content

Latest commit

 

History

History
151 lines (102 loc) · 2.75 KB

File metadata and controls

151 lines (102 loc) · 2.75 KB

Bash

Compression

Create a .tar.gz or .zip file

tar -czvf file.tar.gz directory-to-compress/
zip -r file.zip directory-to-compress/

Extract contents of a .tar.gz or .zip file

tar -zxvf file.tar.gz
unzip file.zip

SSH & GPG

Create SSH key pair and connect SSH with this key

ssh-keygen -f file_name -C "Comment" # prompts for passphrase
ssh-copy-id -i file_name.pub user@host
ssh -i file_name user@host

Import public key of someone

gpg --import some-one.key

See all imported public keys

gpg --list-keys

Encrypt a file

gpg --encrypt --armor -r some-one@server.com file.txt # or
gpg -e -u "Sender Name" -r "Receiver Name" file.txt

Decrypt a file

gpg -d file.txt.gpg            # to show content directly in bash or
gpg -d file.txt.gpg > file.txt # to create decrypted file

Add existing private SSH key to bash

chmod 600 private.key # set permissions to be only read-writable by me
eval $(ssh-agent -s)  # start ssh agent in background
ssh-add private.key   # add SSH private key to bash

Trigger the GPG agent and reauthenticate

echo "test" | gpg --clearsign

Devices

Remount a device in read-write mode:

sudo mount -o remount,rw tiptoi /media/user/tiptoi

PDF

Count the words of a PDF file:

pdftotext myfile.pdf - | wc -w

Password Generation

Quickly create a random string to use for passwords:

date +%s | sha256sum | base64 | head -c 32 ; echo

Get public IP address

sudo apt install curl # on debian/ubuntu if not already available
curl ipinfo.io/ip

Line Endings

Convert all PHP files in the current directory to Unix line endings

find "./" -type f -name '*.php' -execdir dos2unix {} +

Ports

Check which process uses a given port and (optionally) kill it

sudo lsof -i :1234
# COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
# docker-pr 43185 root    7u  IPv4 123123      0t0  TCP *:1234 (LISTEN)
# docker-pr 43198 root    7u  IPv6 123123      0t0  TCP *:1234 (LISTEN)
sudo kill 43185

MySQL

Run database import file on server (corresponding to the phpMyAdmin importer)

mysql -u database_user -p database_name < file.sql
mysql -u database_user -p -h database_host database_name < file.sql # if it's not localhost

Create database export file

mysqldump -u database_user -p database_name > file.sql

PHP

Start PHP's built in webserver for the current directory

php -S 127.0.0.1:8000

Now you can access this directory as root under http://localhost:8000

Python

Update all outdated packages at once

pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U