|
|
@ -16,7 +16,24 @@
|
|
|
|
# limitations under the License. #
|
|
|
|
# limitations under the License. #
|
|
|
|
#--------------------------------------------------------------------------- #
|
|
|
|
#--------------------------------------------------------------------------- #
|
|
|
|
|
|
|
|
|
|
|
|
AUTH_DIR="/root/.ssh"
|
|
|
|
[ -z "${SSH_PUBLIC_KEY}${EC2_PUBLIC_KEY}" ] && exit 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z "${USERNAME}" ]
|
|
|
|
|
|
|
|
then
|
|
|
|
|
|
|
|
USERNAME=root
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get user $HOME directory
|
|
|
|
|
|
|
|
USER_HOME=$(getent passwd "${USERNAME}" | awk -F':' '{print $6}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ -n "${USER_HOME}" ]
|
|
|
|
|
|
|
|
then
|
|
|
|
|
|
|
|
AUTH_DIR="${USER_HOME}/.ssh"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
# Fallback on root
|
|
|
|
|
|
|
|
AUTH_DIR="/root/.ssh"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
AUTH_FILE="$AUTH_DIR/authorized_keys"
|
|
|
|
AUTH_FILE="$AUTH_DIR/authorized_keys"
|
|
|
|
|
|
|
|
|
|
|
|
function add_keys {
|
|
|
|
function add_keys {
|
|
|
@ -41,4 +58,5 @@ if [ -n "$EC2_PUBLIC_KEY" ]; then
|
|
|
|
echo "$EC2_PUBLIC_KEY" | add_keys
|
|
|
|
echo "$EC2_PUBLIC_KEY" | add_keys
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chown "${USERNAME}": ${AUTH_DIR} ${AUTH_FILE}
|
|
|
|
chmod 600 $AUTH_FILE
|
|
|
|
chmod 600 $AUTH_FILE
|
|
|
|