Magellan Linux

Contents of /alx-src/trunk/tinyalxconfig-ng/functions/config_ssh_auth.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 389 - (show annotations) (download) (as text)
Wed Jun 4 17:13:19 2008 UTC (15 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 1728 byte(s)
-using dropbear instead of openssh

1 # $Header: /home/cvsd/alx-cvs/alx-src/tinyalxconfig-ng/functions/config_ssh_auth.sh,v 1.2 2008-06-04 17:13:19 niro Exp $
2 # exchanges the public server and client ssh keys
3
4 gen_keys()
5 {
6 if [ ! -e /etc/dropbear/dropbear_dss_host_key ]
7 then
8 echo -e ${COLOREDSTAR}"Generating DSS-Hostkey ..."
9 /usr/bin/dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key
10 fi
11
12 if [ ! -e /etc/dropbear/dropbear_rsa_host_key ]
13 then
14 echo -e ${COLOREDSTAR}"Generating RSA-Hostkey ..."
15 /usr/bin/dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
16 fi
17
18 if [ ! -e /etc/dropbear/dropbear_rsa_host_key.pub ]
19 then
20 echo -e ${COLOREDSTAR}"Generating Public RSA-Hostkey ..."
21 # note: the key is stored in the second line of the output
22 /usr/bin/dropbearkey -y -f /etc/dropbear/dropbear_rsa_host_key | sed -n '2p' \
23 > /etc/dropbear/dropbear_rsa_host_key.pub
24 fi
25 }
26
27 config_ssh_auth()
28 {
29 local PUB_KEY_SERVER
30 local ID
31
32 # generate evtually missing keys
33 gen_keys
34
35 # write the public key of the server to the host system
36 PUB_KEY_SERVER="$(mysqldo "select public_key from ssh_auth_server where id=1;")"
37
38 if [[ -n ${PUB_KEY_SERVER} ]]
39 then
40 HOME=/root
41 # only if not empty
42 [ ! -d $HOME/.ssh ] && install -d $HOME/.ssh
43 echo "${PUB_KEY_SERVER}" > $HOME/.ssh/authorized_keys
44 fi
45
46 # put the public key of the host into the db
47 ID=$(mysqldo "select serial from ssh_auth_clients where serial=${ALX_SERIAL};")
48
49 if [[ -n ${ID} ]]
50 then
51 # run an update
52 mysqldo "update ssh_auth_clients set public_key='$(< /etc/dropbear/dropbear_rsa_host_key.pub)' where serial=${ALX_SERIAL};"
53 else
54 # run an insert
55 mysqldo "insert into ssh_auth_clients(serial,public_key) values('${ALX_SERIAL}','$(< /etc/ssh/ssh_host_rsa_key.pub)')"
56 fi
57 }