Created
June 26, 2012 17:01
-
-
Save smoser/2997136 to your computer and use it in GitHub Desktop.
rsa2azure: convert ssh key to public key suitable for azure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# vi: ts=4 noexpandtab | |
# rsa2azure | |
Usage() { | |
cat <<EOF | |
Usage: ${0##*/} [options] [private-key] | |
convert private-key in ssh private key format to the format | |
needed by windows azure as described at | |
http://utlemming.azurewebsites.net/?p=91 | |
options: | |
-o | --output FILE write output to F. default stdout. | |
Default private-key is ~/.ssh/id_rsa) | |
EOF | |
} | |
fail() { echo "$@" 1>&2; exit 1; } | |
short_opts="ho:" | |
long_opts="output:,help" | |
getopt_out=$(getopt --name "${0##*/}" \ | |
--options "ho:" --long "output:,help" -- "$@") && | |
eval set -- "${getopt_out}" || | |
{ Usage 1>&2; fail "bad usage"; } | |
umask 066 | |
outfile=/dev/stdout | |
echo $@ | |
while [ $# -ne 0 ]; do | |
case "$1" in | |
-h|--help) Usage; exit 0;; | |
-o|--output) outfile=${2}; shift;; | |
--) shift; break;; | |
esac | |
shift; | |
done | |
[ $# -eq 0 -o $# -eq 1 ] || { Usage 1>&2; exit 1; } | |
key_in=$1 | |
if [ $# -eq 0 ]; then | |
key_in=~/.ssh/id_rsa | |
[ -f "$key_in" ] || fail "no default key found in $key_in"; | |
fi | |
[ "$key_in" = "-" ] && key_in=/dev/stdin | |
[ -f "$key_in" ] || fail "${key_in}: not a file" | |
out=$(openssl rsa -in "$key_in" -out /dev/stdout 2>/dev/null) || | |
fail "failed to decrypt private key in $key_in" | |
printf "%s" "$out" | | |
openssl req -new -x509 -nodes -days 999 -batch -outform DER -batch \ | |
-key /dev/stdin -out "${outfile}" 2>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment