-
Notifications
You must be signed in to change notification settings - Fork 3
/
set_up_ssh_key.sh
executable file
·64 lines (55 loc) · 2.01 KB
/
set_up_ssh_key.sh
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
#!/bin/bash
################################################################################
### Configure SSH key
################################################################################
set -e # Immediately rethrows exceptions
function toClipboard {
if command -v pbcopy > /dev/null; then
pbcopy
elif command -v xclip > /dev/null; then
xclip -i -selection c
else
echo "No clipboard tool found. Here's what you need to paste into the developer console:"
cat -
fi
}
# Generate new SSH key
echo -n "Please enter the email you'd like to register with your GitHub SSH key: "
read email
echo "Next, press enter. Then create a memorable passphrase"
ssh-keygen -t rsa -b 4096 -C "$email"
# Add your SSH key to the ssh-agent
# Start the ssh-agent in the background
eval "$(ssh-agent -s)"
# Automatically load keys into the ssh-agent and store passphrases in the keychain (when in macOS)
# Host *
# AddKeysToAgent yes
# UseKeychain yes
# IdentityFile ~/.ssh/id_rsa
if [[ "$(uname)" == "Darwin" ]]; then
# macOS-specific commands here
printf "Host *\n AddKeysToAgent yes\n UseKeychain yes\n IdentityFile ~/.ssh/id_rsa\n" >> ~/.ssh/config
else
# Linux-specific commands here
printf "Host *\n AddKeysToAgent yes\n IdentityFile ~/.ssh/id_rsa\n" >> ~/.ssh/config
fi
# Add your SSH private key to the ssh-agent and store passphrase in the keychain (when in macOS)
if [[ "$(uname)" == "Darwin" ]]; then
# macOS-specific commands here
ssh-add -K ~/.ssh/id_rsa
else
# Linux-specific commands here
ssh-add ~/.ssh/id_rsa
fi
# Copy the contents of the id_rsa.pub file to clipboard
cat ~/.ssh/id_rsa.pub | toClipboard
echo "Copied SSH key to clipboard!"
# Open the SSH key URL in the default web browser
if command -v open > /dev/null; then
open "https://github.com/settings/ssh/new"
elif command -v xdg-open > /dev/null; then
xdg-open "https://github.com/settings/ssh/new"
else
echo "Please open the following URL in your web browser and paste the SSH public key:"
echo "https://github.com/settings/ssh/new"
fi