Annotation of /alx-src/branches/alxconf-060/functions/config_ssh_auth.sh
Parent Directory | Revision Log
Revision 1800 -
(hide annotations)
(download)
(as text)
Thu Apr 14 19:29:35 2011 UTC (13 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 1536 byte(s)
Thu Apr 14 19:29:35 2011 UTC (13 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 1536 byte(s)
created 0.6.x branch
1 | niro | 342 | # $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 | niro | 253 | # exchanges the public server and client ssh keys |
3 | |||
4 | niro | 342 | gen_keys() |
5 | { | ||
6 | niro | 253 | 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 | niro | 342 | config_ssh_auth() |
26 | { | ||
27 | niro | 254 | local PUB_KEY_SERVER |
28 | local ID | ||
29 | |||
30 | niro | 253 | # generate evtually missing keys |
31 | gen_keys | ||
32 | |||
33 | # write the public key of the server to the host system | ||
34 | niro | 342 | PUB_KEY_SERVER="$(mysqldo "select public_key from ssh_auth_server where id=1;")" |
35 | niro | 253 | |
36 | if [ -n "${PUB_KEY_SERVER}" ] | ||
37 | then | ||
38 | niro | 330 | HOME=/root |
39 | niro | 253 | # 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 | niro | 342 | ID=$(mysqldo "select serial from ssh_auth_clients where serial=${ALX_SERIAL};") |
46 | niro | 253 | |
47 | if [ -n "${ID}" ] | ||
48 | then | ||
49 | niro | 342 | # run an update |
50 | mysqldo "update ssh_auth_clients set public_key='$(< /etc/ssh/ssh_host_rsa_key.pub)' where serial=${ALX_SERIAL};" | ||
51 | niro | 253 | else |
52 | niro | 342 | # run an insert |
53 | mysqldo "insert into ssh_auth_clients(serial,public_key) values('${ALX_SERIAL}','$(< /etc/ssh/ssh_host_rsa_key.pub)')" | ||
54 | niro | 253 | fi |
55 | } |