github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/examples/terraform-ssh-password-example/user_data.sh (about)

     1  #!/usr/bin/env bash
     2  set -euo pipefail
     3  
     4  # Send the log output from this script to user-data.log, syslog, and the console
     5  # From: https://alestic.com/2010/12/ec2-user-data-output/
     6  exec > >(tee /var/log/user-data.log | logger -t user-data -s 2>/dev/console) 2>&1
     7  
     8  # Create our new 'terratest' user
     9  adduser --disabled-password --gecos "" terratest
    10  
    11  # Set the user's password based on the random input from 'test/terraform_ssh_password_example_test.go'
    12  # shellcheck disable=SC2154
    13  echo "terratest:${terratest_password}" | chpasswd
    14  
    15  # Enable password auth on the SSH service
    16  sed -i 's/^PasswordAuthentication no$/PasswordAuthentication yes/g' /etc/ssh/sshd_config
    17  
    18  # Bounce the service to apply the config change
    19  service ssh restart