File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change 2121#
2222# Open SSH Connection
2323# ssh <INSTANCE_USER>@<INSTANCE_ID>
24- #
24+ #
2525# Ensure AWS CLI environment variables are set properly
2626# e.g. AWS_PROFILE='default' ssh ec2-user@i-xxxxxxxxxxxxxxxx
2727#
@@ -52,13 +52,19 @@ aws ssm send-command \
5252 --document-name ' AWS-RunShellScript' \
5353 --comment " Add an SSH public key to authorized_keys for ${ssh_public_key_timeout} seconds" \
5454 --parameters commands=" \"
55- mkdir -p ~${ssh_user} /.ssh && cd ~${ssh_user} /.ssh || exit 1
56-
55+ ssh_user_home=\$ (getent passwd '${ssh_user} ' | cut -d: -f6)
56+ if [ -z \\\"\$ {ssh_user_home}\\\" ]
57+ then
58+ exit 1
59+ fi
60+
61+ mkdir -p \\\"\$ {ssh_user_home}/.ssh\\\" && cd \\\"\$ {ssh_user_home}/.ssh\\\" || exit 1
62+
5763 authorized_key='${ssh_public_key} ssm-session'
5864 echo \\\"\$ {authorized_key}\\\" >> authorized_keys
59-
65+
6066 sleep ${ssh_public_key_timeout}
61-
67+
6268 grep -v -F \\\"\$ {authorized_key}\\\" authorized_keys > .authorized_keys
6369 mv .authorized_keys authorized_keys
6470 \" "
You can’t perform that action at this time.
0 commit comments