Skip to content

Instantly share code, notes, and snippets.

@gregjhogan
gregjhogan / .bashrc_or_.bash_profile.sh
Last active September 30, 2015 20:24
~/.bashrc or ~/.bash_profile
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'
alias proxyssh="ssh $1 -oProxyCommand='ssh access -W %h:%p'"
@gregjhogan
gregjhogan / azure-arm-cli-capture-vm
Last active September 30, 2015 20:23
Azure ARM VM capture
azure vm deallocate <rg> <vm>
azure vm generalize <rg> <vm>
azure vm capture <rg> <vm> <image-prefix>
@gregjhogan
gregjhogan / azure-cli-copy-blob
Last active September 25, 2015 16:07
Azure X-Platform CLI Examples
azure storage container create --connection-string '<dest-cxn>' <dest-container>
azure storage blob copy start --connection-string '<source-cxn>' --source-container <source-container> --source-blob <disk.vhd> --dest-connection-string '<dest-cxn>' --dest-container <dest-container> --dest-blob <disk.vhd>
# watch copy progress
azure storage blob copy show --connection-string '<dest-cxn>' --container <dest-container> --blob <disk.vhd>
@gregjhogan
gregjhogan / socks5-proxy-command
Created September 24, 2015 19:49
Socks5 proxy over SSH
ssh -N -D 1080 <user>@<server>
# HTTP/HTTPS_PROXY=socks5://127.0.0.1:1080
@gregjhogan
gregjhogan / azure-arm-api-through-jump-server
Last active September 25, 2015 05:33
Azure ARM management API through jump server
# add alias for lo0
sudo ifconfig lo0 alias 127.0.1.1 up
sudo ifconfig lo0 alias 127.0.1.2 up
# /etc/hosts alias
127.0.1.1 login.microsoftonline.com
127.0.1.2 management.azure.com
# ssh tunnel
sudo ssh -N -L 127.0.1.1:443:login.microsoftonline.com:443 <user>@<jump-server>
sudo ssh -N -L 127.0.1.2:443:management.azure.com:443 <user>@<jump-server>
@gregjhogan
gregjhogan / azure-cli-deploy-from-template
Last active January 10, 2017 23:03
Azure CLI create group and deploy from template
azure group create <resource-group> <location>
# create storage account for new vm vhds
azure storage account create --location <location> --type GRS --resource-group <resource-group> <name>
# get connection string(s) for following commands
azure storage account connectionstring show --resource-group <resource-group> <name>
azure storage container create --connection-string '<dest-cxn>' vhd-base-images
# copy blob from base image storage account to resource group that new vm will be in
azure storage blob copy start --connection-string '<source-cxn>' --source-container vhd-base-images --source-blob <disk.vhd> --dest-connection-string '<dest-cxn>' --dest-container vhd-base-images
# watch copy progress
azure storage blob copy show --connection-string '<dest-cxn>' --container vhd-base-images --blob <disk.vhd>
@gregjhogan
gregjhogan / azure-cli-create-nsg
Created September 25, 2015 22:08
Azure create NSG allowing SSH and RDP
azure network nsg create --resource-group <resource-group> --location <location> <nsg-name>
azure network nsg rule create --access Allow --protocol Tcp --direction Inbound --priority 100 --source-address-prefix Internet --source-port-range * --destination-address-prefix * --destination-port-range 3389 <resource-group> <nsg-name> allow-rdp
azure network nsg rule create --access Allow --protocol Tcp --direction Inbound --priority 100 --source-address-prefix Internet --source-port-range * --destination-address-prefix * --destination-port-range 22 <resource-group> <nsg-name> allow-ssh
@gregjhogan
gregjhogan / azure-cli-blob-sas-token-url.ps1
Last active September 27, 2015 13:45
Generate blob SAS URL
$cxn = (azure storage account connectionstring show --json --resource-group <resource-group> <storage-account>) | Out-String | ConvertFrom-Json
$sas = (azure storage blob sas create --json -c $cxn.string <container> <blob> r (Get-Date).AddHours(1).ToUniversalTime().ToString("s")) | Out-String | ConvertFrom-Json
$sas.url
@gregjhogan
gregjhogan / .ssh_slash_config
Last active September 30, 2015 20:22
~/.ssh/config
Host *
ServerAliveInterval 15
ControlMaster auto
# make sure you create this directory: mkdir ~/.ssh/multi
ControlPath ~/.ssh/multi/%r@%h-%p
ControlPersist 600
Compression yes
@gregjhogan
gregjhogan / self-extracting_script.sh
Last active November 6, 2023 01:53
self-extracting shell script
# create files in an otherwise empty directory
mkdir files
cd files
touch setup.sh # entry point after extraction
touch file.txt # supporting data used by setup.sh
# create archive
tar -pczf ../archive.tar.gz *
cd ..