-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsshSetup.sh
executable file
·55 lines (49 loc) · 1.54 KB
/
sshSetup.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
#!/bin/sh
if [ -f "$HOME/.ssh/id_rsa" ]; then
printf "[SSH] Pulblic key already exists\n"
else
read -p "[SSH] Create new SSH key (yes/no): " response
if test "$response" = "yes"; then
printf "\n"
read -p "Enter your e-mail: " ssh_email
printf "\n"
printf "[SSH] Creating ssh key\n"
ssh-keygen -t rsa -b 4096 -C $ssh_email
printf "\n"
fi
fi
printf "[SSH] Copying ssh key to pasteboard\n"
if [ "$(uname)" == "Darwin" ]; then
cat ~/.ssh/id_rsa.pub | pbcopy
elif [ "$(uname)" == "Linux" ]; then
if [ -e "/dev/clipboard" ] ; then
cat ~/.ssh/id_rsa.pub > /dev/clipboard
else
echo "[SSH] /dev/clipboard does not exist"
fi
printf "\n"
else
echo "[SSH] Unknown system: $(uname)"
fi
printf "[SSH] Configuring .ssh/configure\n"
touch ~/.ssh/configure
# disconnect after 6 seconds
echo "ServerAliveInterval 3" >> ~/.ssh/configure
echo "ServerAliveCountMax 2" >> ~/.ssh/configure
printf "\n"
printf "[SSH] Setting up ssh key\n"
if [ "$(uname)" == "Darwin" ]; then
# Setup SSH to use keychain to prevent git from always asking for passphrase
# https://superuser.com/questions/1127067/macos-keeps-asking-my-ssh-passphrase-since-i-updated-to-sierra
echo "Host *" >> ~/.ssh/configure
echo " UseKeychain yes" >> ~/.ssh/configure
elif [ "$(uname)" == "Linux" ]; then
printf "[SSH] Adding ssh key to ssh-agent\n"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
printf "\n"
else
echo "[SSH] Unknown system: $(uname)"
fi
printf "[SSH] Done\n"
printf "\n"