Skip to content

Instantly share code, notes, and snippets.

@tylerwalts
Last active December 16, 2020 11:43
Show Gist options
  • Save tylerwalts/7127099 to your computer and use it in GitHub Desktop.
Save tylerwalts/7127099 to your computer and use it in GitHub Desktop.
Bash script to add a ssh key to a user's home ssh config. Used prior to running a puppet librarian as part of a server bootstrap process.
#!/bin/sh
# Place the SSH key for the git service account used to access private repositories
home_path="$(cd && pwd)"
ssh_path="$home_path/.ssh"
mkdir -p $ssh_path
provider="bitbucket.org"
#provider="github.com"
echo "Creating temporary ssh key"
echo "-----BEGIN RSA PRIVATE KEY-----
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
-----END RSA PRIVATE KEY-----" > $ssh_path/git-account-key
echo "Setting perms on ssh key"
chmod 600 $ssh_path/git-account-key
echo "Adding key to user ssh config"
touch ~/.ssh/config
echo "Host $provider
IdentityFile $ssh_path/git-account-key" >> ~/.ssh/config
echo "Adding known host for $provider"
ssh-keyscan -t rsa $provider >> ~/.ssh/known_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment