Generate ssh host keys
From radmind
(Difference between revisions)
(Testing with -s) |
(Added more robust version of script.) |
||
Line 11: | Line 11: | ||
#!/bin/sh | #!/bin/sh | ||
- | + | SSHKEYGEN=/usr/bin/ssh-keygen | |
- | [ ! -s /etc/ssh_host_key ] | + | if [ ! -s /etc/ssh_host_key -o ! -s /etc/ssh_host_key.pub ]; then |
- | + | if [ -f /etc/ssh_host_key ]; then | |
- | [ ! -s /etc/ssh_host_rsa_key ] | + | rm /etc/ssh_host_key |
- | + | fi | |
- | [ ! -s /etc/ssh_host_dsa_key ] | + | 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 | 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