-
Notifications
You must be signed in to change notification settings - Fork 14
/
ssh.sh
43 lines (43 loc) · 1.19 KB
/
ssh.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
#!/bin/bash
#author : Simon Legah
#CopyRights : Landmark Technologies
#Contact : +1 437 215 2483
<<mc
This script will create an upload ssh-keys to githubAPI
It automate the ssh-keygen process for githup.
Shell scripting is goot for automation
Please make you create a token before executing this script.
https://www.youtube.com/watch?v=3YgutlExHRo&t=3632s
watch the youtube video for clarity.
mc
echo "Enter your GitHub Personal Access Token:"
read token
#echo $token >token.txt
#cat token.txt
cat ~/.ssh/id_rsa.pub
#if condition to validate weather ssh keys are already present or not
if [ $? -eq 0 ]
then
echo "SSH Keys are already present..."
else
echo "SSH Keys are are not present..., Create the sshkyes using ssh-keygen command"
ssh-keygen -t rsa
echo "Key successfully generated"
fi
sshkey=`cat ~/.ssh/id_rsa.pub`
if [ $? -eq 0 ]
then
echo "Copying the key to GitHub account"
curl -X POST -H "Content-type: application/json" -d "{\"title\": \"SSHKEY\",\"key\": \"$sshkey\"}" "https://api.github.com/user/keys?access_token=$token"
if [ $? -eq 0 ]
then
echo "Successfully copied the token to GitHub"
exit 0
else
echo "Failed"
exit 1
fi
else
echo "Failure in generating the key"
exit 1
fi