Contents of /alx-src/branches/alxconf-060/functions/config_ssh_auth.sh
Parent Directory | Revision Log
Revision 545 -
(show annotations)
(download)
(as text)
Wed Feb 4 20:07:30 2009 UTC (15 years, 7 months ago) by niro
Original Path: alx-src/branches/alxconf_20060908/functions/config_ssh_auth.sh
File MIME type: application/x-sh
File size: 1536 byte(s)
Wed Feb 4 20:07:30 2009 UTC (15 years, 7 months ago) by niro
Original Path: alx-src/branches/alxconf_20060908/functions/config_ssh_auth.sh
File MIME type: application/x-sh
File size: 1536 byte(s)
moved from subdir to main branch dir
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 | } |