Annotation of /alx-src/tags/alxconf-0_6_4_5/functions/config_ssh_auth.sh
Parent Directory | Revision Log
Revision 2036 -
(hide annotations)
(download)
(as text)
Wed May 11 09:11:25 2011 UTC (13 years ago) by niro
Original Path: alx-src/branches/alxconf-060/functions/config_ssh_auth.sh
File MIME type: application/x-sh
File size: 1442 byte(s)
Wed May 11 09:11:25 2011 UTC (13 years ago) by niro
Original Path: alx-src/branches/alxconf-060/functions/config_ssh_auth.sh
File MIME type: application/x-sh
File size: 1442 byte(s)
-make use of the new addconfig() && clearconfig() functions
1 | niro | 1973 | # $Id$ |
2 | niro | 253 | # exchanges the public server and client ssh keys |
3 | |||
4 | niro | 342 | gen_keys() |
5 | { | ||
6 | niro | 1973 | if [ ! -e /etc/dropbear/dropbear_dss_host_key ] |
7 | niro | 253 | then |
8 | niro | 1973 | echo -e ${COLOREDSTAR}"Generating DSS-Hostkey ..." |
9 | dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key | ||
10 | niro | 253 | fi |
11 | |||
12 | niro | 1973 | if [ ! -e /etc/dropbear/dropbear_rsa_host_key ] |
13 | niro | 253 | then |
14 | niro | 1973 | echo -e ${COLREDSTAR}"Generating RSA-Hostkey ..." |
15 | dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key | ||
16 | niro | 253 | fi |
17 | } | ||
18 | |||
19 | niro | 342 | config_ssh_auth() |
20 | { | ||
21 | niro | 254 | local PUB_KEY_SERVER |
22 | local ID | ||
23 | niro | 1973 | local pubkey |
24 | niro | 2036 | local CONFIG |
25 | niro | 254 | |
26 | niro | 253 | # generate evtually missing keys |
27 | gen_keys | ||
28 | |||
29 | niro | 1973 | # 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 | niro | 253 | # write the public key of the server to the host system |
33 | niro | 342 | PUB_KEY_SERVER="$(mysqldo "select public_key from ssh_auth_server where id=1;")" |
34 | niro | 253 | |
35 | niro | 2036 | if [[ ! -z ${PUB_KEY_SERVER} ]] |
36 | niro | 253 | then |
37 | niro | 330 | HOME=/root |
38 | niro | 253 | # only if not empty |
39 | [ ! -d $HOME/.ssh ] && install -d $HOME/.ssh | ||
40 | niro | 2036 | CONFIG=$HOME/.ssh/authorized_keys |
41 | clearconfig | ||
42 | addconfig "${PUB_KEY_SERVER}" | ||
43 | niro | 253 | fi |
44 | |||
45 | # put the public key of the host into the db | ||
46 | niro | 342 | ID=$(mysqldo "select serial from ssh_auth_clients where serial=${ALX_SERIAL};") |
47 | niro | 253 | |
48 | niro | 2036 | if [[ ! -z ${ID} ]] |
49 | niro | 253 | then |
50 | niro | 342 | # run an update |
51 | niro | 1973 | mysqldo "update ssh_auth_clients set public_key='${pubkey}' where serial=${ALX_SERIAL};" |
52 | niro | 253 | else |
53 | niro | 342 | # run an insert |
54 | niro | 1973 | mysqldo "insert into ssh_auth_clients(serial,public_key) values('${ALX_SERIAL}','${pubkey}')" |
55 | niro | 253 | fi |
56 | } |