Skip to content

Commit

Permalink
Update Bootstrap-RemoteHostViaSSH.ps1 updated wsl sshd script
Browse files Browse the repository at this point in the history
  • Loading branch information
pldmgg authored Nov 29, 2023
1 parent f1f462a commit 68fe898
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions MyScripts/Bootstrap-RemoteHostViaSSH.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,30 @@ New-NetFirewallRule -Name wsl_sshd -DisplayName 'OpenSSH Server (sshd) for WSL'
# Now we want to create a scheduled task that will start WSL AND ssh within WSL on boot
$ScriptOutputPath = "C:\Scripts\bin\wsl_sshd.ps1"
$ScriptContentAsString = @'
# Set Log Info
# Set Log Info and WSL Instance Name
$LogFileDir = "C:\Scripts\logs"
$LogFilePath = $LogFileDir + '\' + 'start_wsl_sshd_' + $(Get-Date -Format MMddyy_hhmmss) + '.log'
$WslInstanceName = "Ubuntu"
# Start SSH service in WSL
bash.exe -c "sudo /usr/sbin/service ssh start"
#wsl --distribution "$WslInstanceName" --user root /bin/sh -c "/usr/sbin/service ssh start"
# Remove port proxy rule
netsh.exe interface portproxy delete v4tov4 listenport=2222 listenaddress=0.0.0.0 protocol=tcp
# Get IP address from WSL
$IP = (wsl.exe hostname -I).Trim()
try {
$IP = (wsl.exe hostname -I).Trim()
#$IPPrep = wsl --distribution "$WslInstanceName" --user root /bin/sh -c "ip addr show eth0 | grep 'inet ' | awk '{print `$2}' | cut -d/ -f1"
#$IPPrep = bash.exe -c "ip addr show eth0 | grep 'inet ' | awk '{print `$2}' | cut -d/ -f1"
#$IP = ($IPPrep -split "[\s]")[-1].Trim()
} catch {
$ErrMsg = $_.Exception.Message
$null = Add-Content -Path $LogFilePath -Value $ErrMsg
Write-Error $ErrMsg
return
}
if (!$IP) {
$null = Add-Content -Path $LogFilePath -Value 'Unable to identify wsl IP Address via: (wsl.exe hostname -I).Trim()'
Expand Down

0 comments on commit 68fe898

Please sign in to comment.