Lorsque vous déployez un serveur dédié chez OVH et décidez d'utiliser le template Windows Core, il est nécessaire d'automatiser certaines étapes dès l'installation de Windows par le template OVH pour renforcer la sécurité et vous octroyer un accès SSH.
Voici comment procéder à l'installation d'un serveur Windows Server 2025 Standard/Datacenter (Core) avec un script de post-installation adapté à l'environnement OVH.
# Définir le mot de passe Administrateur Windows
$AdminUser = Get-LocalUser | Where-Object { $_.Sid.Value.EndsWith('-500') }
$AdminUser | Enable-LocalUser
$Password = ConvertTo-SecureString "MOT2PASSE-ADMINISTRATEUR-BALAISE" -AsPlainText -Force
$AdminUser | Set-LocalUser -Password $Password
# Désactiver sconfig au démarrage du serveur
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name "Shell" -Value "powershell.exe"
# Installer & Configurer le serveur OpenSSH
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*' | Add-WindowsCapability -Online
Set-Service -Name sshd -StartupType 'Automatic'
Start-Service sshd
$authorizedKey = 'ssh-ed25519 VOTRE-CLEF-PUBLIQUE utilisateur@VOTRE-PC'
Add-Content -Force -Path C:\ProgramData\ssh\administrators_authorized_keys -Value $authorizedKey
icacls.exe C:\ProgramData\ssh\administrators_authorized_keys /inheritance:r /grant *S-1-5-32-544:F /grant SYSTEM:F
# Renforcer la configuration d'OpenSSH
$sshdConfigPath = 'C:\ProgramData\ssh\sshd_config'
$linesToUncomment = @(
'LoginGraceTime',
'PubkeyAuthentication yes',
'MaxAuthTries',
'MaxSessions',
'Banner none'
)
(Get-Content -Path $sshdConfigPath) | ForEach-Object {
$line = $_
foreach ($entry in $linesToUncomment) {
# Remplacer la ligne commentée correspondante
$pattern = "^\s*#\s*($entry.*)$"
if ($line -match $pattern) {
$line = $Matches[1]
break
}
}
$line
} | Set-Content -Path $sshdConfigPath -Encoding ascii
function Set-SSHDConfigOption {
param (
[string]$Path,
[string]$Option,
[string]$Value
)
# Si l'option existe (commentée ou non), remplace-la
if (Select-String -Path $Path -Pattern "^\s*#?\s*$Option\s") {
(Get-Content -Path $Path) |
ForEach-Object { $_ -replace "^\s*#?\s*$Option\s.*", "$Option $Value" } |
Set-Content -Path $Path -Encoding ascii
}
# Sinon, ajoute-la en fin de fichier
else {
Add-Content -Path $Path -Value "$Option $Value"
}
}
Set-SSHDConfigOption -Path $sshdConfigPath -Option "Port" -Value "64111"
New-NetFirewallRule -Name "OpenSSH-Inbound" -DisplayName "OpenSSH-Inbound" -Protocol TCP -Direction Inbound -Action Allow -LocalPort 64111
Set-SSHDConfigOption -Path $sshdConfigPath -Option "LoginGraceTime" -Value "3s"
Set-SSHDConfigOption -Path $sshdConfigPath -Option "MaxAuthTries" -Value "3"
Set-SSHDConfigOption -Path $sshdConfigPath -Option "MaxSessions" -Value "3"
Set-SSHDConfigOption -Path $sshdConfigPath -Option "PasswordAuthentication" -Value "no"
Set-SSHDConfigOption -Path $sshdConfigPath -Option "ClientAliveInterval" -Value "300"
Set-SSHDConfigOption -Path $sshdConfigPath -Option "ClientAliveCountMax" -Value "2"
Restart-Service sshd
# Installer Bitlocker
Install-WindowsFeature BitLocker
# Renommer Serveur
Rename-Computer -NewName "MON-SUPER-SERVEUR" -Force
Restart-Computer -Force
Le script commence par définir un mot de passe sécurisé pour le compte administrateur local (MOT2PASSE-ADMINISTRATEUR-BALAISE). A vous de le changer.
L'environnement graphique simplifié est remplacé par une invite PowerShell directe pour faciliter les interventions en ligne de commande. Libre à vous de ne pas inclure cette partie.
Le script ajuste plusieurs paramètres de sécurité dans le fichier de configuration SSH (sshd_config) tels que :
Le script crée une règle spécifique pour autoriser les connexions entrantes uniquement sur le port SSH sécurisé choisi.
Pour sécuriser davantage les données sensibles sur le serveur, le script installe BitLocker.
Attention : si votre OS est installé sur un Soft Raid, alors vous ne pourrez pas utiliser Bitlocker !
Enfin, le serveur est renommé automatiquement en MON-SUPER-SERVEUR puis redémarre pour finaliser toutes les configurations appliquées.
Une fois le serveur installé, le script de post-installation va s'exécuter et le serveur redémarrera.
Vous pourrez vous connecter via SSH à l'issue
Les MAJ sont bloquées ou non fonctionnelles à cause du template Windows Serveur Core d'OVH !
Pour pouvoir installer la dernière cumulative, il est nécessaire de disposer du checkpoint de septembre 2024 en plus, où votre cumulative actuelle ne s'installera.
Prenons la cumulative de juin 2025 pour exemple.
Aller sur le catalogue officiel : https://www.catalog.update.microsoft.com/
Rechercher, récupérer l'URL et Télécharger les KB suivantes directement sur votre serveur Core :
Puis, installer uniquement la cumulative.
Les dépendances nécessaires seront trouvées dans le checkpoint de septembre 2024.
New-Item C:\TEMP
Set-Location C:\TEMP
Invoke-WebRequest -Uri https://catalog.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/d8b7f92b-bd35-4b4c-96e5-46ce984b31e0/public/windows11.0-kb5043080-x64_953449672073f8fb99badb4cc6d5d7849b9c83e8.msu -Outfile windows11.0-kb5043080-x64_953449672073f8fb99badb4cc6d5d7849b9c83e8.msu
Invoke-WebRequest -Uri https://catalog.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/58b46d94-e497-4048-8aea-4b430fd63d12/public/windows11.0-kb5060842-x64_07871bda98c444c14691e0a90560306703b739cf.msu -Outfile windows11.0-kb5060842-x64_07871bda98c444c14691e0a90560306703b739cf.msu
Add-WindowsPackage -Online -PackagePath C:\TEMP\windows11.0-kb5060842-x64_07871bda98c444c14691e0a90560306703b739cf.msu
Restart-Computer -Force