forked from driesvints/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-ssh
executable file
·35 lines (30 loc) · 1.55 KB
/
generate-ssh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
source "${PWD}/helpers/trap_and_trace.sh"
PATH="${PWD}:$PATH"
log_attention "Enter your email address to generate a new SSH key."
until [[ "${confirm:-}" == "y" ]]; do
read -p "Your email address: " USER_ID
log_attention "Your SSH key will be generated for the following USER ID: ${USER_ID}"
read -p "Is this correct? [y/n] " confirm
done
# Generating a new SSH key
# https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key
log_info "Generating a new SSH key for ID ${USER_ID}"
ssh-keygen -t ed25519 -C $USER_ID -f ~/.ssh/id_ed25519 -N ""
# Adding your SSH key to the ssh-agent
# https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent
if [[ -n $(command -v ssh-agent 2>/dev/null) ]]; then
log_info "Adding your SSH key to the ssh-agent"
eval "$(ssh-agent -s)"
else
log_attention "ssh-agent not found; skipping adding SSH key to the ssh-agent"
fi
log_info "Registering your SSH key"
touch ~/.ssh/config
echo "Host *\n AddKeysToAgent yes\n UseKeychain yes\n IdentityFile ~/.ssh/id_ed25519" | tee ~/.ssh/config
ssh-add -K ~/.ssh/id_ed25519
# Adding your SSH key to your GitHub account
# https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account
log_success "SSH key generated. To add your public key to GitHub, etc., run 'pbcopy < ~/.ssh/id_ed25519.pub' to copy the key to your clipboard."