Annotation of /alx-src/branches/alxconf_20060908/functions/config_ssh_auth.sh
Parent Directory | Revision Log
Revision 254 -
(hide annotations)
(download)
(as text)
Thu Apr 14 21:23:36 2005 UTC (19 years, 5 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/functions/config_ssh_auth.sh
File MIME type: application/x-sh
File size: 1749 byte(s)
Thu Apr 14 21:23:36 2005 UTC (19 years, 5 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/functions/config_ssh_auth.sh
File MIME type: application/x-sh
File size: 1749 byte(s)
fixed some global var which shall be local vars
1 | niro | 254 | # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_ssh_auth.sh,v 1.2 2005-04-14 21:23:36 niro Exp $ |
2 | niro | 253 | # 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 | niro | 254 | local PUB_KEY_SERVER |
27 | local ID | ||
28 | |||
29 | niro | 253 | # 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 | # only if not empty | ||
39 | [ ! -d $HOME/.ssh ] && install -d $HOME/.ssh | ||
40 | echo "${PUB_KEY_SERVER}" > $HOME/.ssh/authorized_keys | ||
41 | fi | ||
42 | |||
43 | |||
44 | # put the public key of the host into the db | ||
45 | ID=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ | ||
46 | "select serial from ssh_auth_clients where serial=${ALX_SERIAL};") | ||
47 | |||
48 | if [ -n "${ID}" ] | ||
49 | then | ||
50 | #run an update | ||
51 | mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ | ||
52 | "update ssh_auth_clients set public_key='$(< /etc/ssh/ssh_host_rsa_key.pub)' where serial=${ALX_SERIAL};" | ||
53 | else | ||
54 | #run an insert | ||
55 | mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ | ||
56 | "insert into ssh_auth_clients(serial,public_key) values('${ALX_SERIAL}','$(< /etc/ssh/ssh_host_rsa_key.pub)')" | ||
57 | fi | ||
58 | } |