Skip to content

Instantly share code, notes, and snippets.

@ravage
Last active October 13, 2019 09:33
Show Gist options
  • Save ravage/eaef6a7572aa8272948d to your computer and use it in GitHub Desktop.
Save ravage/eaef6a7572aa8272948d to your computer and use it in GitHub Desktop.

Generate Random Password

openssl rand -hex 16

Ruby: Single Line HTTP Server

ruby -run -e httpd . -p 8000

Python: Single Line HTTP Server

python -m SimpleHTTPServer 8080
python3 -m http.server 8080

OSX: Route Network Through Interface

route add -net 192.168.1 -interface ppp0

OpenSSL: Dump Certificate Contents

openssl x509 -in <certificate> -text

OSX: No Icons On Desktop

defaults write com.apple.finder CreateDesktop false; killall Finder

OSX: Disable Bonjour Advertising

sudo /usr/libexec/PlistBuddy -c "Add :ProgramArguments: string --no-multicast" /System/Library/LaunchDaemons/com.apple.discoveryd.plist

OSX: Wake SDCard Reader

sudo kextunload -b com.apple.driver.AppleUSBCardReader

OpenStack: List Namespaces

ip netns list

OpenStack: Execute Command On Namespace

ip netns exec <namespace> <command>

SSH: Remove Key From known_hosts

ssh-keygen -R <hash> or <host>

SSH: Extract Public Key

ssh-keygen -y -f /path/to/private.key > /path/to/public.key

SH: Generate Random MAC Address

openssl rand -hex 5 | sed -e 's/\(..\)/:\1/g; s/^/fe/'

LXC: Execute Command Inside Container

virsh -c lxc:/// lxc-enter-namespace <domain> -- /absolute/path/to/command

LXC: Rename

virsh dumpxml <domain> > <domain>.xml
<edit domain.xml, change the name>
virsh undefine <domain>
virsh define <domain>.xml

Linux: Extract RPM

rpm2cpio <file>.rpm | cpio -idmv

Synology: Restart Service

/usr/syno/sbin/synoservicectl --restart <service>

Linux: Watch IO Operations

watch -n 1 "(ps aux | awk '\$8 ~ /D/  { print \$0 }')"

SELinux: Set Type TYPE in the Target Security Context

semanage fcontext -a -t <context> </path>
restorecon -v </path>

OpenSSL: Strong DH Group

openssl dhparam -out dhparams.pem 2048

OpenStack: Export Glance Image

glance image-download --file <filename> <image id>

NFS: "RPC: AUTH_GSS upcall failed. Please check user daemon is running."

Quick "fix": echo "blacklist rpcsec_gss_krb5" >> /etc/modprobe.d/blacklist.conf; rmmod rpcsec_gss_krb5

OSX: Flush DNS Cache

dscacheutil -flushcache
sudo killall -HUP mDNSResponder

QEMU: User Managed VMs

echo "allow <bridge interface> >> /etc/qemu-kvm/bridge.conf"

QEMU: Working virsh console

Add console=tty0 console=ttyS0,115200n8 to grub and update boot

echo "T0:123:respawn:/sbin/getty -L ttyS0 115200 vt100 >> /etc/inittab"

Libvirt: Attach cdrom

virsh attach-disk <domain> <source> <destination> --type cdrom --mode readonly

Ping With Time And Log

while true; do ping -n -W1 -c1 <host> | grep rtt | sed -e "s/^/`date +"[%d-%m-%Y %H:%M:%S]"` /"; sleep <seconds>;done | tee <file>

OSX Alias

sudo ifconfig <interface> alias <address> <netmask>
sudo ifconfig <interface> -alias <address>

OpenSSL: Dump Certificate Content

openssl x509 -in <certificate> -text

Debian: Clean Old Kernels

apt-get remove --purge linux-image-<#>.<#>.<#>-<#>-generic

Tmux: Reload Config

Hit Ctrl+b then :
source-file ~/.tmux.conf

Mojave Font Rendering

defaults write -g CGFontRenderingFontSmoothingDisabled -bool FALSE

Git: Global gitignore

git config --global core.excludesfile ~/.gitignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment