Generate ssh host keys
From radmind
(Difference between revisions)
(Testing with -s) |
(Added header comments) |
||
(2 intermediate revisions not shown.) | |||
Line 1: | Line 1: | ||
- | This script will generate ssh host keys if they | + | This script will generate ssh host keys if they 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 | ||
Line 10: | Line 10: | ||
<pre> | <pre> | ||
#!/bin/sh | #!/bin/sh | ||
+ | # sshd-key-gen.sh | ||
+ | # post-apply script that properly manages ssh authentication keys | ||
+ | # Install in /var/radmind/postapply | ||
- | + | 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> |
Current revision
This script will generate ssh host keys if they 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 # sshd-key-gen.sh # post-apply script that properly manages ssh authentication keys # Install in /var/radmind/postapply 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