Created
October 31, 2019 01:24
-
-
Save mousavian/14d88458b6f01ed870d4c301a39de4b2 to your computer and use it in GitHub Desktop.
Removes passphrase from private key (Supports OpenSSH and RSA)
This file contains 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/bash | |
# Usage: | |
# RSA: | |
# ./bare.sh my-priv-key -t rsa | |
# | |
# OpenSSH | |
# ./bare.sh my-priv-key -t openssh | |
# | |
# "my-priv-key.naked" will be generate | |
function main { | |
priv_key="$1"; shift | |
priv_key_naked="${priv_key}.naked" | |
while [ "$1" != "" ]; do | |
case $1 in | |
--type | -t) shift | |
if [ "$1" = "rsa" ]; then | |
use_rsa "$priv_key" "$priv_key_naked" | |
elif [ "$1" = "openssh" ]; then | |
use_openssh "$priv_key" "$priv_key_naked" | |
else | |
echo "Unknown Type. Please provide --type=[rsa|openssh]" | |
usage | |
exit 1 | |
fi | |
exit | |
;; | |
--help | -h) shift | |
usage | |
;; | |
*) | |
echo "Unkown command" | |
usage | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
usage | |
} | |
function use_rsa { | |
local priv_key="$1" | |
local priv_key_naked="$2" | |
openssl rsa -in "${priv_key}" -out "${priv_key_naked}" | |
} | |
function use_openssh { | |
local priv_key="$1" | |
local priv_key_naked="$2" | |
cp "${priv_key}" "${priv_key_naked}" | |
chmod 600 "${priv_key_naked}" | |
ssh-keygen -p -f "${priv_key_naked}" -N "" | |
} | |
function usage { | |
echo "usage: bare.sh my-priv-key --type [rsa|openssh] | [-h]" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment