-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh-key-setup.sh
More file actions
31 lines (23 loc) · 819 Bytes
/
Copy pathssh-key-setup.sh
File metadata and controls
31 lines (23 loc) · 819 Bytes
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
#!/bin/sh
EMAIL=$1
# Info: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
if [ -z "$EMAIL" ]; then
echo "No email argument supplied"
exit 1
fi
# check if ssh key already exists
if [ -f "$HOME/.ssh/id_ed25519" ]; then
echo "SSH Key already exists. Skipping SSH Key Generation."
exit 0
fi
# generate ssh key using ed25519 algorithm
# -C set email, -N empty passcode, -q quiet
ssh-keygen -q -t ed25519 -C "$EMAIL" -f $HOME/.ssh/id_ed25519 -N ""
# start ssh-agent in the background
eval "$(ssh-agent -s)"
# add ssh key
sudo ssh-add -K $HOME/.ssh/id_ed25519
# print public key to add
echo "SSH Key created and added to agent. Add public key to remote (GitHub, GitLab, etc.)"
echo "Public Key:"
cat $HOME/.ssh/id_ed25519.pub