Annotation of /alx-src/trunk/tinyalxconfig-ng/functions/config_ssh_auth.sh
Parent Directory | Revision Log
Revision 390 -
(hide annotations)
(download)
(as text)
Wed Jun 4 17:19:37 2008 UTC (16 years, 3 months ago) by niro
File MIME type: application/x-sh
File size: 1738 byte(s)
Wed Jun 4 17:19:37 2008 UTC (16 years, 3 months ago) by niro
File MIME type: application/x-sh
File size: 1738 byte(s)
-missed one
1 | niro | 390 | # $Header: /home/cvsd/alx-cvs/alx-src/tinyalxconfig-ng/functions/config_ssh_auth.sh,v 1.3 2008-06-04 17:19:37 niro Exp $ |
2 | niro | 386 | # exchanges the public server and client ssh keys |
3 | |||
4 | gen_keys() | ||
5 | { | ||
6 | niro | 389 | if [ ! -e /etc/dropbear/dropbear_dss_host_key ] |
7 | niro | 386 | then |
8 | niro | 389 | echo -e ${COLOREDSTAR}"Generating DSS-Hostkey ..." |
9 | /usr/bin/dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key | ||
10 | niro | 386 | fi |
11 | |||
12 | niro | 389 | if [ ! -e /etc/dropbear/dropbear_rsa_host_key ] |
13 | niro | 386 | then |
14 | niro | 389 | echo -e ${COLOREDSTAR}"Generating RSA-Hostkey ..." |
15 | /usr/bin/dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key | ||
16 | niro | 386 | fi |
17 | |||
18 | niro | 389 | if [ ! -e /etc/dropbear/dropbear_rsa_host_key.pub ] |
19 | niro | 386 | then |
20 | niro | 389 | 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 | niro | 386 | 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 | niro | 389 | if [[ -n ${PUB_KEY_SERVER} ]] |
39 | niro | 386 | 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 | niro | 389 | if [[ -n ${ID} ]] |
50 | niro | 386 | then |
51 | # run an update | ||
52 | niro | 389 | mysqldo "update ssh_auth_clients set public_key='$(< /etc/dropbear/dropbear_rsa_host_key.pub)' where serial=${ALX_SERIAL};" |
53 | niro | 386 | else |
54 | # run an insert | ||
55 | niro | 390 | mysqldo "insert into ssh_auth_clients(serial,public_key) values('${ALX_SERIAL}','$(< /etc/dropbear/dropbear_rsa_host_key.pub)')" |
56 | niro | 386 | fi |
57 | } |