ssh-over-ssm icon indicating copy to clipboard operation
ssh-over-ssm copied to clipboard

Bash script leaves a blank line after deletion of temporary key

Open yohancourbe opened this issue 2 years ago • 0 comments

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

yohancourbe avatar Jul 28 '22 15:07 yohancourbe