Chase Qi | 7c3f889 | 2019-02-21 17:19:32 +0800 | [diff] [blame] | 1 | #!/bin/sh -ex |
| 2 | |
| 3 | TEST_DIR=$(dirname "$(realpath "$0")") |
| 4 | # shellcheck disable=SC1090 |
| 5 | . "${TEST_DIR}/../../lib/sh-test-lib" |
| 6 | |
| 7 | # On unsupported distros, installation will be skipped by default. |
| 8 | install_deps openssh-server |
| 9 | |
| 10 | # Add id_rsa.pub key sent by host to authorized_keys. |
| 11 | pub_key=$(grep "pub_key" /tmp/lava_multi_node_cache.txt | awk -F"=" '{print $NF}') |
| 12 | mkdir -p ~/.ssh/ |
| 13 | echo "ssh-rsa ${pub_key} fuego-lava" > ~/.ssh/authorized_keys |
| 14 | chmod 600 ~/.ssh/authorized_keys |
| 15 | |
| 16 | # Enabled root login. |
| 17 | if ! grep "^PermitRootLogin yes" /etc/ssh/sshd_config; then |
| 18 | # Enable root login. |
| 19 | sed -i 's/^# *PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config |
| 20 | sed -i 's/^ *PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config |
| 21 | |
| 22 | # Restart ssh. |
| 23 | dist_name |
| 24 | # shellcheck disable=SC2154 |
| 25 | case "${dist}" in |
| 26 | debian|ubuntu|fedora|centos) |
| 27 | systemctl restart ssh |
| 28 | systemctl status ssh |
| 29 | ;; |
| 30 | *) |
| 31 | warning_msg "Unknown distro: ${dist}, attempting to restart ssh..." |
| 32 | /etc/init.d/ssh restart || true |
| 33 | service ssh restart || true |
| 34 | ;; |
| 35 | esac |
| 36 | sleep 3 |
| 37 | fi |
| 38 | |