Magellan Linux

Annotation of /alx-src/trunk/alxconfig-ng/functions/config_ssh_auth.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 253 - (hide annotations) (download) (as text)
Thu Apr 14 19:13:04 2005 UTC (19 years, 1 month ago) by niro
File MIME type: application/x-sh
File size: 1716 byte(s)
new; ssh key exchange functions for remote reboot/shutdown

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