File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed
aws_rdp_member_server_with_worker Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -133,10 +133,16 @@ resource "aws_instance" "member_server" {
133
133
$AuthorizedKey = (Invoke-WebRequest -Uri 'http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key' -Headers $ImdsHeaders -UseBasicParsing).Content
134
134
$AuthorizedKeysPath = 'C:\ProgramData\ssh\administrators_authorized_keys'
135
135
New-Item -Path $AuthorizedKeysPath -ItemType File -Value $AuthorizedKey -Force
136
+ # Set the correct permissions on the authorized_keys file
137
+ icacls "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r
138
+ icacls "C:\ProgramData\ssh\administrators_authorized_keys" /grant "Administrators:F" /grant "SYSTEM:F"
139
+ icacls "C:\ProgramData\ssh\administrators_authorized_keys" /remove "Users"
140
+ icacls "C:\ProgramData\ssh\administrators_authorized_keys" /remove "Authenticated Users"
136
141
137
142
# Ensure the SSH agent pulls in the new key.
138
143
Set-Service -Name ssh-agent -StartupType "Automatic"
139
144
Restart-Service -Name ssh-agent
145
+ Restart-Service -Name sshd
140
146
141
147
# Open the firewall for SSH connections
142
148
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Original file line number Diff line number Diff line change @@ -158,10 +158,16 @@ resource "aws_instance" "worker" {
158
158
$AuthorizedKey = (Invoke-WebRequest -Uri 'http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key' -Headers $ImdsHeaders -UseBasicParsing).Content
159
159
$AuthorizedKeysPath = 'C:\ProgramData\ssh\administrators_authorized_keys'
160
160
New-Item -Path $AuthorizedKeysPath -ItemType File -Value $AuthorizedKey -Force
161
+ # Set the correct permissions on the authorized_keys file
162
+ icacls "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r
163
+ icacls "C:\ProgramData\ssh\administrators_authorized_keys" /grant "Administrators:F" /grant "SYSTEM:F"
164
+ icacls "C:\ProgramData\ssh\administrators_authorized_keys" /remove "Users"
165
+ icacls "C:\ProgramData\ssh\administrators_authorized_keys" /remove "Authenticated Users"
161
166
162
167
# Ensure the SSH agent pulls in the new key.
163
168
Set-Service -Name ssh-agent -StartupType "Automatic"
164
169
Restart-Service -Name ssh-agent
170
+ Restart-Service -Name sshd
165
171
166
172
# Open the firewall for SSH
167
173
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Original file line number Diff line number Diff line change @@ -160,8 +160,8 @@ resource "aws_instance" "client" {
160
160
161
161
# Set up SSH so we can remotely manage the instance
162
162
## Install OpenSSH Server and Client
163
- # Loop to make sure that SSH installs correctly
164
- $elapsed = 0
163
+ # Loop to make sure that SSH installs correctly
164
+ $elapsed = 0
165
165
do {
166
166
try {
167
167
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
@@ -215,10 +215,16 @@ resource "aws_instance" "client" {
215
215
$AuthorizedKey = (Invoke-WebRequest -Uri 'http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key' -Headers $ImdsHeaders -UseBasicParsing).Content
216
216
$AuthorizedKeysPath = 'C:\ProgramData\ssh\administrators_authorized_keys'
217
217
New-Item -Path $AuthorizedKeysPath -ItemType File -Value $AuthorizedKey -Force
218
+ # Set the correct permissions on the authorized_keys file
219
+ icacls "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r
220
+ icacls "C:\ProgramData\ssh\administrators_authorized_keys" /grant "Administrators:F" /grant "SYSTEM:F"
221
+ icacls "C:\ProgramData\ssh\administrators_authorized_keys" /remove "Users"
222
+ icacls "C:\ProgramData\ssh\administrators_authorized_keys" /remove "Authenticated Users"
218
223
219
224
## Ensure the SSH agent pulls in the new key.
220
225
Set-Service -Name ssh-agent -StartupType "Automatic"
221
226
Restart-Service -Name ssh-agent
227
+ Restart-Service -Name sshd
222
228
223
229
## Open the firewall for SSH connections
224
230
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
You can’t perform that action at this time.
0 commit comments