-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_git_ssh.sh
More file actions
40 lines (33 loc) Β· 1.12 KB
/
setup_git_ssh.sh
File metadata and controls
40 lines (33 loc) Β· 1.12 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
#!/bin/bash
git_name="username"
git_email="example@gmail.com"
KEY_FILE="$HOME/.ssh/id_ed25519"
echo "π§ Setting Git global config..."
git config --global user.name "$git_name"
git config --global user.email "$git_email"
echo "β
Git config set: $git_name <$git_email>"
if [ -f "$KEY_FILE" ]; then
echo "π SSH key already exists at $KEY_FILE"
else
echo "π¨ Generating new SSH key..."
ssh-keygen -t ed25519 -C "$git_email" -f "$KEY_FILE" -N ""
fi
echo "π Starting ssh-agent..."
eval "$(ssh-agent -s)"
echo "β Adding SSH private key to agent..."
ssh-add "$KEY_FILE"
echo "π Copying SSH public key to clipboard..."
if command -v xclip &>/dev/null; then
xclip -sel clip < "${KEY_FILE}.pub"
echo "β
Public key copied using xclip."
elif command -v pbcopy &>/dev/null; then
pbcopy < "${KEY_FILE}.pub"
echo "β
Public key copied using pbcopy."
else
echo "β οΈ Clipboard utility not found. Here's your public key:"
cat "${KEY_FILE}.pub"
fi
echo ""
echo "π Add this key to GitHub: https://github.com/settings/keys"
read -p "Press Enter to test SSH connection to GitHub..."
ssh -T git@github.com