Skip to content

Commit f9c60c7

Browse files
authored
fix: fix key cleanup
1 parent 0e53c8b commit f9c60c7

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

aws-ssm-ssh-proxy-command.ps1

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ if ($splitted_instance.Length -gt 1) {
2020
$env:AWS_DEFAULT_REGION = $splitted_instance[1]
2121
}
2222

23-
Write-Output "Add public key $ssh_public_key_path for $ssh_user at instance $instance_id for 60 seconds"
23+
Write-Output "Add public key $ssh_public_key_path for $ssh_user at instance $instance_id for 10 seconds"
2424
$ssh_public_key = (Get-Content $ssh_public_key_path | Select-Object -first 1)
2525
aws ssm send-command `
2626
--instance-ids "$instance_id" `
2727
--document-name 'AWS-RunShellScript' `
28-
--comment "Add an SSH public key to authorized_keys for 60 seconds" `
28+
--comment "Add an SSH public key to authorized_keys for 10 seconds" `
2929
--parameters commands=@"
3030
\"
3131
set -eu
@@ -36,10 +36,10 @@ aws ssm send-command `
3636
3737
echo \\\"`$authorized_key\\\" >> authorized_keys
3838
39-
sleep 60
39+
sleep 10
4040
41-
grep -v -F \\\"`$authorized_key\\\" authorized_keys > ~authorized_keys
42-
mv ~authorized_keys authorized_keys
41+
(grep -v -F \\\"\${authorized_key}\\\" authorized_keys || true) > authorized_keys~
42+
mv authorized_keys~ authorized_keys
4343
\"
4444
"@
4545

aws-ssm-ssh-proxy-command.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ then
1919
instance_id="${instance_id%%${REGION_SEPARATOR}*}"
2020
fi
2121

22-
>/dev/stderr echo "Add public key ${ssh_public_key_path} for ${ssh_user} at instance ${instance_id} for 60 seconds"
22+
>/dev/stderr echo "Add public key ${ssh_public_key_path} for ${ssh_user} at instance ${instance_id} for 10 seconds"
2323
ssh_public_key="$(cat "${ssh_public_key_path}")"
2424
aws ssm send-command \
2525
--instance-ids "${instance_id}" \
2626
--document-name 'AWS-RunShellScript' \
27-
--comment "Add an SSH public key to authorized_keys for 60 seconds" \
27+
--comment "Add an SSH public key to authorized_keys for 10 seconds" \
2828
--parameters commands="
2929
\"
3030
set -eu
@@ -35,10 +35,10 @@ aws ssm send-command \
3535
3636
echo \\\"\${authorized_key}\\\" >> authorized_keys
3737
38-
sleep 60
38+
sleep 10
3939
40-
grep -v -F \\\"\${authorized_key}\\\" authorized_keys > ~authorized_keys
41-
mv ~authorized_keys authorized_keys
40+
(grep -v -F \\\"\${authorized_key}\\\" authorized_keys || true) > authorized_keys~
41+
mv authorized_keys~ authorized_keys
4242
\"
4343
"
4444

0 commit comments

Comments
 (0)