Skip to content

Commit 39f956c

Browse files
authored
Update aws-ssm-ec2-proxy-command.sh
1 parent ec0d928 commit 39f956c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

aws-ssm-ec2-proxy-command.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ ssh_user="$2"
3838
ssh_port="$3"
3939
ssh_public_key_path="$4"
4040
ssh_public_key="$(cat "${ssh_public_key_path}")"
41+
ssh_public_key_timeout=60
4142

4243
if echo "${ec2_instance_id}" | grep -qe "${REGION_SEPARATOR}"
4344
then
@@ -49,13 +50,15 @@ fi
4950
aws 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
\""

0 commit comments

Comments
 (0)