Contents of /alx-src/branches/alxconf-060/functions/config_ssh_auth.sh
Parent Directory | Revision Log
Revision 330 -
(show annotations)
(download)
(as text)
Wed Sep 7 19:14:24 2005 UTC (19 years ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/functions/config_ssh_auth.sh
File MIME type: application/x-sh
File size: 1762 byte(s)
Wed Sep 7 19:14:24 2005 UTC (19 years ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/functions/config_ssh_auth.sh
File MIME type: application/x-sh
File size: 1762 byte(s)
added HOME=/root as $HOME is not defined on system boot
1 | # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_ssh_auth.sh,v 1.3 2005-09-07 19:14:18 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 | local PUB_KEY_SERVER |
27 | local ID |
28 | |
29 | # generate evtually missing keys |
30 | gen_keys |
31 | |
32 | # write the public key of the server to the host system |
33 | PUB_KEY_SERVER="$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
34 | "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 | |
45 | # put the public key of the host into the db |
46 | ID=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
47 | "select serial from ssh_auth_clients where serial=${ALX_SERIAL};") |
48 | |
49 | if [ -n "${ID}" ] |
50 | then |
51 | #run an update |
52 | mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
53 | "update ssh_auth_clients set public_key='$(< /etc/ssh/ssh_host_rsa_key.pub)' where serial=${ALX_SERIAL};" |
54 | else |
55 | #run an insert |
56 | mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
57 | "insert into ssh_auth_clients(serial,public_key) values('${ALX_SERIAL}','$(< /etc/ssh/ssh_host_rsa_key.pub)')" |
58 | fi |
59 | } |