-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetssh.sh
55 lines (48 loc) · 1.37 KB
/
setssh.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/bash
echo "
##############################################################################
## Set SSH keys
## User: $USER (e.g.: ubuntu, svven, ducu, jon etc.)
##############################################################################"
if [ $# -lt 1 ]; then
echo "## Missing arguments:
## 1 - User private (deployment) key (i.e. URL to id_rsa)
## Optional:
## 2 - User public key for SSH access (i.e. URL to id_rsa.pub)
##############################################################################"
exit 1
fi
PRIVATE_KEY=$1; PUBLIC_KEY=$2
DIR=$( cd "$( dirname "$0" )" && pwd )
## Go home
cd $HOME # /home/$USER
## Prepare ssh directory
if [ ! -d .ssh ]; then
mkdir .ssh
chmod 700 .ssh
fi
## Add known hosts
if [ ! -f .ssh/known_hosts ]; then
touch .ssh/known_hosts
chmod 600 .ssh/known_hosts
fi
ssh-keygen -R github.org
ssh-keyscan -H github.org >> .ssh/known_hosts
ssh-keygen -R bitbucket.org
ssh-keyscan -H bitbucket.org >> .ssh/known_hosts
## Set private key
if [ $PRIVATE_KEY ]; then
curl -L $PRIVATE_KEY > .ssh/id_rsa
chmod 600 .ssh/id_rsa
fi
## Set ssh agent
if [ ! -f .bash_profile ]; then
touch .bash_profile
cat $DIR/startagent.sh > .bash_profile
fi
## Set public key (optional)
if [ $PUBLIC_KEY ]; then
curl -L $PUBLIC_KEY > .ssh/id_rsa.pub
cat .ssh/id_rsa.pub > .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
fi