Created
November 8, 2012 11:11
-
-
Save mshytikov/4038216 to your computer and use it in GitHub Desktop.
get cert from remote server and install it to local machine
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 | |
| # | |
| # usage: install_cert.sh remote.host.name | |
| # aggregated from: | |
| # - http://stackoverflow.com/questions/699576/validating-parameters-to-a-bash-script | |
| # - https://help.ubuntu.com/community/OpenSSL | |
| # - http://www.madboa.com/geek/openssl/#cert-retrieve | |
| die () { | |
| echo >&2 "$@" | |
| exit 1 | |
| } | |
| REMHOST=$1 | |
| REMPORT=${2:-443} | |
| CERT="$1.crt" | |
| [ "$#" -eq 1 ] || die "1 argument required, $# provided" | |
| openssl s_client -connect ${REMHOST}:${REMPORT} 2>&1 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ${CERT} | |
| sudo cp $CERT /usr/share/ca-certificates/$CERT | |
| sudo dpkg-reconfigure ca-certificates | |
| sudo update-ca-certificates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment