Table of Contents

Linux Tips

Assorted useful commands and tips for linux

Files

dd: copy an iso to or erase a disk (/dev/sda)

dd if=/path/to/iso.iso of=/dev/sda status=progress  # Flash
dd if=/dev/zero of=/dev/sda status=progress         # Erase

dd: create a file of a specific size (megabytes)

dd if=/dev/zero of=/path/to/file.bin bs=1M count=123 status=progress

nc: fast and dirty send a file

nc -lvkp 8888 > file.ext  # On destination

cat file | nc DST_HOST 8888   # On source

SSH

SSH is amazing!

Generate a private key

ssh-keygen

Get your ssh keys onto a remote system

ssh-copy-id host1
cat .ssh/id_rsa.pub | ssh mxsmp.com 'cat >> .ssh/authorized_keys'

From github! first add your key to github (you should do this)

ssh-import-id-gh GITHUB_USERNAME

if you dont have `ssh-import-id`

curl https://github.com/GITHUB_USERNAME.keys >> .ssh/authorized_keys

Jump off of a system

ssh -J host1 host2

Forward a local port to remote system (curl 127.0.0.1:1234 goes to remote:10.1.2.3:1337)

 ssh -L1234:10.1.2.3:1337 host

Forward a remote port to local (on remote, curl 127.0.0.1:7777 goes to local 192.168.1.2:8888)

ssh -R7777:192.168.1.2:8888

SSH config

Host example.com server1            # use `ssh example.com` or `ssh server`
    HostName 1.2.3.4                # Override the host to ssh to
    User root                       # Override default username
    Port 1234                       # Override default port
    ProxyJump HOST2                 # Always proxy jump off of specific host
    LocalForward 8080 10.0.0.1:443  # Forward local 8080 to remote 10.0.0.1:443
    IdentityFile ~/.ssh/jump.priv   # Use a specific private key
    UserKnownHostsFile /dev/null    # Do not save known hosts
    StrictHostKeyChecking no        # Do not check known hosts (use with previous)

Examples

User potato                       # Use potato by default instead of username

Host jump-gateway                 # ssh jump-gateway
    HostName gateway.my-server.com
    User jump
    Port 2222

Host internal-server              # ssh internal-server == ssh -J jump-gateway cyber@10.3.2.1
    HostName 10.3.2.1
    ProxyJump jump-gateway
    User cyber

Host 10.20.*                      # for all 10.20.x.x hosts, login as root, do not check host key
    User root                     # useful in a subnet where *TRUSTED* vms are constantly being recreated
    UserKnownHostsFile /dev/null
    StrictHostKeyChecking no

Scripting

Useful scripting snippets

Script must be run as root

[[ $EUID -ne 0 ]] && echo "Need root" && exit 1

Force apt to not ask questions (automated installs)

export DEBIAN_FRONTEND=noninteractive
export TZ=Etc/UTC

apt install -y PACKAGE