File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ ssh_user="$2"
3838ssh_port=" $3 "
3939ssh_public_key_path=" $4 "
4040ssh_public_key=" $( cat " ${ssh_public_key_path} " ) "
41+ ssh_public_key_timeout=60
4142
4243if echo " ${ec2_instance_id} " | grep -qe " ${REGION_SEPARATOR} "
4344then
4950aws ssm send-command \
5051 --instance-ids " ${ec2_instance_id} " \
5152 --document-name ' AWS-RunShellScript' \
52- --comment " Add an SSH public key to authorized_keys for 60 seconds" \
53+ --comment " Add an SSH public key to authorized_keys for ${ssh_public_key_timeout} seconds" \
5354 --parameters commands=" \"
54- mkdir -p ~${ssh_user} /.ssh
55- cd ~ ${ssh_user} /.ssh || exit 1
55+ mkdir -p ~${ssh_user} /.ssh && cd $_ || exit 1
56+
5657 authorized_key='${ssh_public_key} ssm-session'
5758 echo \\\"\$ {authorized_key}\\\" >> authorized_keys
58- sleep 60
59+
60+ sleep ${ssh_public_key_timeout}
61+
5962 grep -v -F \\\"\$ {authorized_key}\\\" authorized_keys > .authorized_keys
6063 mv .authorized_keys authorized_keys
6164 \" "
You can’t perform that action at this time.
0 commit comments