forked from driesvints/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate-ssh
More file actions
executable file
·75 lines (66 loc) · 3.37 KB
/
generate-ssh
File metadata and controls
executable file
·75 lines (66 loc) · 3.37 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/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."
# check_github_keys() {
# print_progress "Checking Github Keys..."
# if [ -f ~/.ssh/id_ed25519.pub ]; then
# print_success "You already have a public key at ~/.ssh/id_ed25519.pub"
# else
# print_progress "Generating new SSH key..."
# if check_err "ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N \"\""; then
# print_failure "Failed to generate new SSH key."
# return
# fi
# if [[ $PLATFORM = "Darwin" ]]; then
# if check_err "ssh-add --apple-use-keychain ~/.ssh/id_ed25519"; then
# print_failure "Failed to run ssh-add on newly generated key."
# return
# fi
# else
# if check_err "eval \"ssh-agent -s\""; then
# print_failure "Failed to start ssh-agent."
# return
# fi
# if check_err "ssh-add ~/.ssh/id_ed25519"; then
# print_failure "Failed to run ssh-add on newly generated key."
# return
# fi
# fi
# print_success "New SSH key pair generated. Public key is at ~/.ssh/id_ed25519.pub"
# fi
# print_warning "If you haven't already added an SSH key to GitHub, follow these steps:"
# printf "1. Go to https://github.com/settings/ssh/new.\n"
# printf "2. Give your key a title ('default' is okay), make sure 'Authentication Key' is selected, and copy the following key into the 'Key' box:\n"
# cat ~/.ssh/id_ed25519.pub
# printf "3. Click on 'Add SSH key' and enter your GitHub password if prompted.\n"
# printf "4. Authorize the SSH key for SSO by clicking 'Configure SSO', then 'Authorize', then following the prompts.\n\n"
# printf "Press ENTER after you've completed these steps (or if you've already added an SSH key to GitHub)...\n"
# read _
# }