Project

General

Profile

Download (953 Bytes) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/sh
2
# Script which sets up password-less logins for ssh host
3
###########################################################################
4

    
5
. ${PROGDIR}/backend/functions.sh
6

    
7
SSHUSER=$1
8
SSHHOST=$2
9
SSHPORT=$3
10

    
11
if [ -z "${SSHUSER}" -o -z "${SSHHOST}" -o -z "${SSHPORT}" ]
12
then
13
  echo "ERROR: Usage setup-ssh-keys <user> <host> <port>"
14
  exit 150
15
fi
16

    
17
cd ~
18

    
19
echo "Preparing to setup SSH key authorization..."
20
echo "When prompted, enter your password for ${SSHUSER}@${SSHHOST}"
21

    
22
if [ ! -e ".ssh/id_rsa.pub" ]
23
then
24
  mkdir .ssh >/dev/null 2>/dev/null
25
  ssh-keygen -q -t rsa -N '' -f .ssh/id_rsa
26
  sleep 1
27
fi
28

    
29
if [ ! -e ".ssh/id_rsa.pub" ]
30
then
31
  echo "ERROR: Failed creating .ssh/id_rsa.pub"
32
  exit 150
33
fi
34

    
35
# Get the .pub key
36
PUBKEY="`cat .ssh/id_rsa.pub`"
37

    
38
ssh -p ${SSHPORT} ${SSHUSER}@${SSHHOST} "mkdir .ssh ; echo $PUBKEY >> .ssh/authorized_keys; chmod 600 .ssh/authorized_keys ; echo $PUBKEY >> .ssh/authorized_keys2; chmod 600 .ssh/authorized_keys2"
(13-13/20)