Last active
March 22, 2021 00:45
-
-
Save adikari/6f3fb7b7518840426deedc042b860d58 to your computer and use it in GitHub Desktop.
generate ssh key and copy to s3 bucket
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/bash | |
set -eou pipefail | |
CURRENT_DIR=$(pwd) | |
ROOT_DIR="$( dirname "${BASH_SOURCE[0]}" )"/.. | |
BUCKET_NAME="buildkite-secrets-adikari" | |
KEY="id_rsa_buildkite" | |
echo "creating bucket $BUCKET_NAME.." | |
aws s3 mb s3://$BUCKET_NAME | |
# Generate SSH Key | |
ssh-keygen -t rsa -b 4096 -f $KEY -N '' | |
# Copy SSH Keys to S3 bucket | |
aws s3 cp --acl private --sse aws:kms $KEY "s3://$BUCKET_NAME/private_ssh_key" | |
aws s3 cp --acl private --sse aws:kms $KEY.pub "s3://$BUCKET_NAME/public_key.pub" | |
if [[ "$OSTYPE" == "darwin"* ]]; then | |
pbcopy < id_rsa_buildkite.pub | |
echo "public key contents copied in clipboard." | |
else | |
cat id_rsa_buildkite.pub | |
fi | |
# Move SSH Keys to ~/.ssh directory | |
mv ./$KEY* ~/.ssh | |
chmod 600 ~/.ssh/$KEY | |
chmod 644 ~/.ssh/$KEY.pub | |
cd $CURRENT_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment