Using SSH to connect to a link-local IPv6 address

It turns out that the self-assigned IPv6 addresses you see are not unique; they're only guaranteed unique on each interface. To ssh to one, you'd need to run:

ssh fe80::21c:c0ff:fe52:c5ec%eth0

for example, where %eth0 specifies eth0.


Using command line switches in bash scripts

I have a number of bash scripts that do useful things to lists of items, such as this:


By using shift, I can have the script run through various IP addresses, for example. But I wanted more. I wanted the same command to sometimes take -t tag as an option and do something different. It turns out there's a relatively easy way to do this using the getopts builtin in bash. However, while it easily found the option (if present), it ruined the shifting feature, until I figured it out. Here's a snippet that sets TAG if -t tag is present, and then is ready to be shifted through as normal.

while getopts "t:h" OPTIONNAME; do
case "$OPTIONNAME" in
t) TAG="$OPTARG";;
[?]) help;;

shift $(($OPTIND - 1))

At this point, you can use $1 as normal; it will be the first non-option parameter. Additional options can be specified in a similar manner.

Bypassing SSH host key checks and the SSH agent

Sometimes you have too many SSH keys loaded, and trying to SSH to a box will fail. Sometimes you're trying to SSH to a box that's been rebooted into another OS or from a rescue CD.

The following command will disable key-based authentication, and ignore your known_hosts file:

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o'RSAAuthentication=no' -o 'PubkeyAuthentication=no'