ssh-over-ssm
ssh-over-ssm copied to clipboard
Bash script leaves a blank line after deletion of temporary key
The sed
command sent to the instance by SSM will leave an empty line on the authorized keys of the instance. I changed the approach a little bit by adding a random alphanumerical identifier to end of the line (like I was setting a key alias)
printf '${ssh_public_key} ${key_id}\\n'|tee -a ${x}/.ssh/authorized_keys || exit 1
This avoids any /
in the sed
arguments and lets me use the deletion subcommand which doesn't leave any empty line.
(sleep 15 && sed -i /${key_id}$/d ${x}/.ssh/authorized_keys &) >/dev/null 2>&1