Generate ssh host keys

From radmind

(Difference between revisions)
Jump to: navigation, search
(Testing with -s)
(Added more robust version of script.)
Line 11: Line 11:
#!/bin/sh
#!/bin/sh
-
SSH-KEYGEN=/usr/bin/ssh-keygen
+
SSHKEYGEN=/usr/bin/ssh-keygen
-
[ ! -s /etc/ssh_host_key ]    && $SSH-KEYGEN -q -t rsa1 \
+
if [ ! -s /etc/ssh_host_key -o ! -s /etc/ssh_host_key.pub ]; then
-
    -f /etc/ssh_host_key -N "" -C "" < /dev/null > /dev/null 2> /dev/null
+
     if [ -f /etc/ssh_host_key ]; then
-
[ ! -s /etc/ssh_host_rsa_key ] && $SSH-KEYGEN -q -t rsa  \
+
rm /etc/ssh_host_key
-
    -f /etc/ssh_host_rsa_key -N "" -C "" < /dev/null > /dev/null 2> /dev/null
+
    fi
-
[ ! -s /etc/ssh_host_dsa_key ] && $SSH-KEYGEN -q -t dsa \
+
    if [ -f /etc/ssh_host_key.pub ]; then
-
    -f /etc/ssh_host_dsa_key -N "" -C "" < /dev/null > /dev/null 2> /dev/null
+
rm /etc/ssh_host_key.pub
 +
    fi
 +
    $SSHKEYGEN -q -t rsa1 -f /etc/ssh_host_key -N "" \
 +
        -C "" < /dev/null > /dev/null 2> /dev/null
 +
    echo "Created /etc/ssh_host_key"
 +
fi
 +
 
 +
if [ ! -s /etc/ssh_host_rsa_key -o ! -s /etc/ssh_host_rsa_key.pub ]; then
 +
    if [ -f /etc/ssh_host_rsa_key ]; then
 +
rm /etc/ssh_host_rsa_key
 +
    fi
 +
    if [ -f /etc/ssh_host_rsa_key.pub ]; then
 +
rm /etc/ssh_host_rsa_key.pub
 +
    fi
 +
    $SSHKEYGEN -q -t rsa  -f /etc/ssh_host_rsa_key -N "" \
 +
        -C "" < /dev/null > /dev/null 2> /dev/null
 +
    echo "Created /etc/ssh_host_rsa_key"
 +
fi
 +
 
 +
if [ ! -s /etc/ssh_host_dsa_key -o ! -s /etc/ssh_host_dsa_key.pub ]; then
 +
    if [ -f /etc/ssh_host_dsa_key ]; then
 +
rm /etc/ssh_host_dsa_key
 +
    fi
 +
    if [ -f /etc/ssh_host_dsa_key.pub ]; then
 +
rm /etc/ssh_host_dsa_key.pub
 +
    fi
 +
    $SSHKEYGEN -q -t dsa -f /etc/ssh_host_dsa_key -N "" \
 +
        -C "" < /dev/null > /dev/null 2> /dev/null
 +
    echo "Created /etc/ssh_host_dsa_key"
 +
fi
exit 0
exit 0
</pre>
</pre>

Revision as of 08:45, 30 May 2007

This script will generate ssh host keys if they files are missing or empty. To use this script, add the following files to a negative transcript:

  • ./private/etc/ssh_host_dsa_key
  • ./private/etc/ssh_host_dsa_key.pub
  • ./private/etc/ssh_host_key
  • ./private/etc/ssh_host_key.pub
  • ./private/etc/ssh_host_rsa_key
  • ./private/etc/ssh_host_rsa_key.pub
#!/bin/sh

SSHKEYGEN=/usr/bin/ssh-keygen

if [ ! -s /etc/ssh_host_key -o ! -s /etc/ssh_host_key.pub ]; then
    if [ -f /etc/ssh_host_key ]; then
	rm /etc/ssh_host_key
    fi
    if [ -f /etc/ssh_host_key.pub ]; then
	rm /etc/ssh_host_key.pub
    fi
    $SSHKEYGEN -q -t rsa1 -f /etc/ssh_host_key -N "" \
        -C "" < /dev/null > /dev/null 2> /dev/null
    echo "Created /etc/ssh_host_key"
fi

if [ ! -s /etc/ssh_host_rsa_key -o ! -s /etc/ssh_host_rsa_key.pub ]; then
    if [ -f /etc/ssh_host_rsa_key ]; then
	rm /etc/ssh_host_rsa_key
    fi
    if [ -f /etc/ssh_host_rsa_key.pub ]; then
	rm /etc/ssh_host_rsa_key.pub
    fi
    $SSHKEYGEN -q -t rsa  -f /etc/ssh_host_rsa_key -N "" \
        -C "" < /dev/null > /dev/null 2> /dev/null
    echo "Created /etc/ssh_host_rsa_key"
fi

if [ ! -s /etc/ssh_host_dsa_key -o ! -s /etc/ssh_host_dsa_key.pub ]; then
    if [ -f /etc/ssh_host_dsa_key ]; then
	rm /etc/ssh_host_dsa_key
    fi
    if [ -f /etc/ssh_host_dsa_key.pub ]; then
	rm /etc/ssh_host_dsa_key.pub
    fi
    $SSHKEYGEN -q -t dsa -f /etc/ssh_host_dsa_key -N "" \
        -C "" < /dev/null > /dev/null 2> /dev/null
    echo "Created /etc/ssh_host_dsa_key"
fi

exit 0
Personal tools