Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 342 - (show annotations) (download) (as text)
Sun Oct 9 21:30:41 2005 UTC (18 years, 7 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/functions/config_ssh_auth.sh
File MIME type: application/x-sh
File size: 1536 byte(s)
- fixed whitespaces
- using now mysqldo from mysqlfunctions

1 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_ssh_auth.sh,v 1.4 2005-10-09 21:30:41 niro Exp $
2 # exchanges the public server and client ssh keys
3
4 gen_keys()
5 {
6 if [ ! -e /etc/ssh/ssh_host_key ]
7 then
8 echo -e ${COLOREDSTAR}"Generating SSH-Hostkey ..."
9 /usr/bin/ssh-keygen -t rsa1 -b 1024 -f /etc/ssh/ssh_host_key -N ''
10 fi
11
12 if [ ! -e /etc/ssh/ssh_host_dsa_key ]
13 then
14 echo -e ${COLREDSTAR}"Generating DSA-Hostkey ..."
15 /usr/bin/ssh-keygen -d -f /etc/ssh/ssh_host_dsa_key -N ''
16 fi
17
18 if [ ! -e /etc/ssh/ssh_host_rsa_key ]
19 then
20 echo -e ${COLOREDSTAR}"Generating RSA-Hostkey ..."
21 /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
22 fi
23 }
24
25 config_ssh_auth()
26 {
27 local PUB_KEY_SERVER
28 local ID
29
30 # generate evtually missing keys
31 gen_keys
32
33 # write the public key of the server to the host system
34 PUB_KEY_SERVER="$(mysqldo "select public_key from ssh_auth_server where id=1;")"
35
36 if [ -n "${PUB_KEY_SERVER}" ]
37 then
38 HOME=/root
39 # only if not empty
40 [ ! -d $HOME/.ssh ] && install -d $HOME/.ssh
41 echo "${PUB_KEY_SERVER}" > $HOME/.ssh/authorized_keys
42 fi
43
44 # put the public key of the host into the db
45 ID=$(mysqldo "select serial from ssh_auth_clients where serial=${ALX_SERIAL};")
46
47 if [ -n "${ID}" ]
48 then
49 # run an update
50 mysqldo "update ssh_auth_clients set public_key='$(< /etc/ssh/ssh_host_rsa_key.pub)' where serial=${ALX_SERIAL};"
51 else
52 # run an insert
53 mysqldo "insert into ssh_auth_clients(serial,public_key) values('${ALX_SERIAL}','$(< /etc/ssh/ssh_host_rsa_key.pub)')"
54 fi
55 }