Magellan Linux

Contents of /alx-src/branches/alxconf-060/functions/config_ssh_auth.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3485 - (show annotations) (download) (as text)
Mon Apr 16 08:46:22 2012 UTC (12 years ago) by niro
File MIME type: application/x-sh
File size: 1421 byte(s)
-use low chars for local variables
1 # $Id$
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 rc_print "Generating DSS-Hostkey ..."
9 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 rc_print "Generating RSA-Hostkey ..."
15 dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
16 fi
17 }
18
19 config_ssh_auth()
20 {
21 local pub_key_server
22 local id
23 local pubkey
24 local CONFIG
25
26 # generate evtually missing keys
27 gen_keys
28
29 # read the pubkey (the sed prints only the second line, which is the pubkey)
30 pubkey="$(dropbearkey -y -f /etc/dropbear/dropbear_rsa_host_key | sed -n '2p')"
31
32 # write the public key of the server to the host system
33 pub_key_server="$(mysqldo "select public_key from ssh_auth_server where id=1;")"
34
35 if [[ ! -z ${pub_key_server} ]]
36 then
37 HOME="/root"
38 # only if not empty
39 [ ! -d $HOME/.ssh ] && install -d $HOME/.ssh
40 CONFIG="$HOME/.ssh/authorized_keys"
41 clearconfig
42 addconfig "${pub_key_server}"
43 fi
44
45 # put the public key of the host into the db
46 id=$(mysqldo "select serial from ssh_auth_clients where serial=${ALX_SERIAL};")
47
48 if [[ ! -z ${id} ]]
49 then
50 # run an update
51 mysqldo "update ssh_auth_clients set public_key='${pubkey}' where serial=${ALX_SERIAL};"
52 else
53 # run an insert
54 mysqldo "insert into ssh_auth_clients(serial,public_key) values('${ALX_SERIAL}','${pubkey}')"
55 fi
56 }