Contents of /alx-src/branches/alxconf-060/functions/config_ssh_auth.sh
Parent Directory | Revision Log
Revision 1973 -
(show annotations)
(download)
(as text)
Sat May 7 11:02:49 2011 UTC (13 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 1398 byte(s)
Sat May 7 11:02:49 2011 UTC (13 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 1398 byte(s)
-support dropbear and dropped openssh
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 | echo -e ${COLOREDSTAR}"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 | echo -e ${COLREDSTAR}"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 | |
25 | # generate evtually missing keys |
26 | gen_keys |
27 | |
28 | # read the pubkey (the sed prints only the second line, which is the pubkey) |
29 | pubkey="$(dropbearkey -y -f /etc/dropbear/dropbear_rsa_host_key | sed -n '2p')" |
30 | |
31 | # write the public key of the server to the host system |
32 | PUB_KEY_SERVER="$(mysqldo "select public_key from ssh_auth_server where id=1;")" |
33 | |
34 | if [ -n "${PUB_KEY_SERVER}" ] |
35 | then |
36 | HOME=/root |
37 | # only if not empty |
38 | [ ! -d $HOME/.ssh ] && install -d $HOME/.ssh |
39 | echo "${PUB_KEY_SERVER}" > $HOME/.ssh/authorized_keys |
40 | fi |
41 | |
42 | # put the public key of the host into the db |
43 | ID=$(mysqldo "select serial from ssh_auth_clients where serial=${ALX_SERIAL};") |
44 | |
45 | if [ -n "${ID}" ] |
46 | then |
47 | # run an update |
48 | mysqldo "update ssh_auth_clients set public_key='${pubkey}' where serial=${ALX_SERIAL};" |
49 | else |
50 | # run an insert |
51 | mysqldo "insert into ssh_auth_clients(serial,public_key) values('${ALX_SERIAL}','${pubkey}')" |
52 | fi |
53 | } |