diff options
Diffstat (limited to 'meta/recipes-connectivity')
-rw-r--r-- | meta/recipes-connectivity/openssh/openssh/init | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/meta/recipes-connectivity/openssh/openssh/init b/meta/recipes-connectivity/openssh/openssh/init index 1f63725cc0..386628afc8 100644 --- a/meta/recipes-connectivity/openssh/openssh/init +++ b/meta/recipes-connectivity/openssh/openssh/init | |||
@@ -19,10 +19,24 @@ fi | |||
19 | [ -z "$SYSCONFDIR" ] && SYSCONFDIR=/etc/ssh | 19 | [ -z "$SYSCONFDIR" ] && SYSCONFDIR=/etc/ssh |
20 | mkdir -p $SYSCONFDIR | 20 | mkdir -p $SYSCONFDIR |
21 | 21 | ||
22 | HOST_KEY_RSA=$SYSCONFDIR/ssh_host_rsa_key | 22 | parse_sshd_opts() { |
23 | HOST_KEY_DSA=$SYSCONFDIR/ssh_host_dsa_key | 23 | set -- ${SSHD_OPTS} -- |
24 | HOST_KEY_ECDSA=$SYSCONFDIR/ssh_host_ecdsa_key | 24 | sshd_config=/etc/ssh/sshd_config |
25 | HOST_KEY_ED25519=$SYSCONFDIR/ssh_host_ed25519_key | 25 | while true ; do |
26 | case "$1" in | ||
27 | -f*) if [ "$1" = "-f" ] ; then | ||
28 | sshd_config="$2" | ||
29 | shift | ||
30 | else | ||
31 | sshd_config="${1#-f}" | ||
32 | fi | ||
33 | shift | ||
34 | ;; | ||
35 | --) shift; break;; | ||
36 | *) shift;; | ||
37 | esac | ||
38 | done | ||
39 | } | ||
26 | 40 | ||
27 | check_for_no_start() { | 41 | check_for_no_start() { |
28 | # forget it if we're trying to start, and /etc/ssh/sshd_not_to_be_run exists | 42 | # forget it if we're trying to start, and /etc/ssh/sshd_not_to_be_run exists |
@@ -45,21 +59,45 @@ check_config() { | |||
45 | } | 59 | } |
46 | 60 | ||
47 | check_keys() { | 61 | check_keys() { |
62 | # parse location of keys | ||
63 | local HOST_KEY_RSA | ||
64 | local HOST_KEY_DSA | ||
65 | local HOST_KEY_ECDSA | ||
66 | local HOST_KEY_ED25519 | ||
67 | |||
68 | parse_sshd_opts | ||
69 | HOST_KEY_RSA=$(grep ^HostKey "${sshd_config}" | grep _rsa_ | tail -1 | awk ' { print $2 } ') | ||
70 | [ -z "${HOST_KEY_RSA}" ] && HOST_KEY_RSA=$(grep HostKey "${sshd_config}" | grep _rsa_ | tail -1 | awk ' { print $2 } ') | ||
71 | [ -z "${HOST_KEY_RSA}" ] && HOST_KEY_RSA=$SYSCONFDIR/ssh_host_rsa_key | ||
72 | HOST_KEY_DSA=$(grep ^HostKey "${sshd_config}" | grep _dsa_ | tail -1 | awk ' { print $2 } ') | ||
73 | [ -z "${HOST_KEY_DSA}" ] && HOST_KEY_DSA=$(grep HostKey "${sshd_config}" | grep _dsa_ | tail -1 | awk ' { print $2 } ') | ||
74 | [ -z "${HOST_KEY_DSA}" ] && HOST_KEY_DSA=$SYSCONFDIR/ssh_host_dsa_key | ||
75 | HOST_KEY_ECDSA=$(grep ^HostKey "${sshd_config}" | grep _ecdsa_ | tail -1 | awk ' { print $2 } ') | ||
76 | [ -z "${HOST_KEY_ECDSA}" ] && HOST_KEY_ECDSA=$(grep HostKey "${sshd_config}" | grep _ecdsa_ | tail -1 | awk ' { print $2 } ') | ||
77 | [ -z "${HOST_KEY_ECDSA}" ] && HOST_KEY_ECDSA=$SYSCONFDIR/ssh_host_ecdsa_key | ||
78 | HOST_KEY_ED25519=$(grep ^HostKey "${sshd_config}" | grep _ed25519_ | tail -1 | awk ' { print $2 } ') | ||
79 | [ -z "${HOST_KEY_ED25519}" ] && HOST_KEY_ED25519=$(grep HostKey "${sshd_config}" | grep _ed25519_ | tail -1 | awk ' { print $2 } ') | ||
80 | [ -z "${HOST_KEY_ED25519}" ] && HOST_KEY_ED25519=$SYSCONFDIR/ssh_host_ed25519_key | ||
81 | |||
48 | # create keys if necessary | 82 | # create keys if necessary |
49 | if [ ! -f $HOST_KEY_RSA ]; then | 83 | if [ ! -f $HOST_KEY_RSA ]; then |
50 | echo " generating ssh RSA key..." | 84 | echo " generating ssh RSA key..." |
85 | mkdir -p $(dirname $HOST_KEY_RSA) | ||
51 | ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa | 86 | ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa |
52 | fi | 87 | fi |
53 | if [ ! -f $HOST_KEY_ECDSA ]; then | 88 | if [ ! -f $HOST_KEY_ECDSA ]; then |
54 | echo " generating ssh ECDSA key..." | 89 | echo " generating ssh ECDSA key..." |
90 | mkdir -p $(dirname $HOST_KEY_ECDSA) | ||
55 | ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa | 91 | ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa |
56 | fi | 92 | fi |
57 | if [ ! -f $HOST_KEY_DSA ]; then | 93 | if [ ! -f $HOST_KEY_DSA ]; then |
58 | echo " generating ssh DSA key..." | 94 | echo " generating ssh DSA key..." |
95 | mkdir -p $(dirname $HOST_KEY_DSA) | ||
59 | ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa | 96 | ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa |
60 | fi | 97 | fi |
61 | if [ ! -f $HOST_KEY_ED25519 ]; then | 98 | if [ ! -f $HOST_KEY_ED25519 ]; then |
62 | echo " generating ssh ED25519 key..." | 99 | echo " generating ssh ED25519 key..." |
100 | mkdir -p $(dirname $HOST_KEY_ED25519) | ||
63 | ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 | 101 | ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519 |
64 | fi | 102 | fi |
65 | } | 103 | } |