Skip to content

Instantly share code, notes, and snippets.

@aolszowka
Forked from MartinSGill/dockerfile
Created January 15, 2021 17:17
Show Gist options
  • Save aolszowka/329b991a610e2ecc10cfc1a540937535 to your computer and use it in GitHub Desktop.
Save aolszowka/329b991a610e2ecc10cfc1a540937535 to your computer and use it in GitHub Desktop.
Example Dockerfile for SSH Server on Windows Server Core
FROM microsoft/windowsservercore:1709
# Install Powershell
ADD https://github.com/PowerShell/PowerShell/releases/download/v6.0.0/PowerShell-6.0.0-win-x64.zip c:/powershell.zip
RUN powershell.exe -Command Expand-Archive c:/powershell.zip c:/PS6 ; Remove-Item c:/powershell.zip
RUN C:/PS6/pwsh.EXE -Command C:/PS6/Install-PowerShellRemoting.ps1
# Install SSH
ADD https://github.com/PowerShell/Win32-OpenSSH/releases/download/0.0.24.0/OpenSSH-Win64.zip c:/openssh.zip
RUN c:/PS6/pwsh.exe -Command Expand-Archive c:/openssh.zip c:/ ; Remove-Item c:/openssh.zip
RUN c:/PS6/pwsh.exe -Command c:/OpenSSH-Win64/Install-SSHd.ps1
# Configure SSH
COPY sshd_config c:/OpenSSH-Win64/sshd_config
COPY sshd_banner c:/OpenSSH-Win64/sshd_banner
WORKDIR c:/OpenSSH-Win64/
# Don't use powershell as -f paramtere causes problems.
RUN c:/OpenSSH-Win64/ssh-keygen.exe -t dsa -N "" -f ssh_host_dsa_key && \
c:/OpenSSH-Win64/ssh-keygen.exe -t rsa -N "" -f ssh_host_rsa_key && \
c:/OpenSSH-Win64/ssh-keygen.exe -t ecdsa -N "" -f ssh_host_ecdsa_key && \
c:/OpenSSH-Win64/ssh-keygen.exe -t ed25519 -N "" -f ssh_host_ed25519_key
# Create a user to login, as containeradministrator password is unknown
RUN net USER ssh "Passw0rd" /ADD && net localgroup "Administrators" "ssh" /ADD
# Set PS6 as default shell
RUN C:/PS6/pwsh.EXE -Command \
New-Item -Path HKLM:\SOFTWARE -Name OpenSSH -Force; \
New-ItemProperty -Path HKLM:\SOFTWARE\OpenSSH -Name DefaultShell -Value c:\ps6\pwsh.exe -PropertyType string -Force ;
RUN C:/PS6/pwsh.EXE -Command \
./Install-sshd.ps1; \
./FixHostFilePermissions.ps1 -Confirm:$false;
EXPOSE 22
# For some reason SSH stops after build. So start it again when container runs.
CMD [ "c:/ps6/pwsh.exe", "-NoExit", "-Command", "Start-Service" ,"sshd" ]
=============================================================================================
##### ##### # # # # ###
# # # # # # ##### #### # # # # # # ##### #### # # #### ###
# # # # # # # # # # # ## # # # # # # # # ###
##### ##### ####### # # # # # # # # # # # # # # # # #### #
# # # # # # # # # # # # # # # # # # # ## # #
# # # # # # # # # # # # # # ## # # # # ## ## # # ###
##### ##### # # # #### ## ## # # # ##### #### # # #### ###
=============================================================================================
* login as ssh / Passw0rd
Port 22
Protocol 2
LogLevel DEBUG
# Authentication:
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#RSAAuthentication yes
#PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
PermitEmptyPasswords yes
Banner sshd_banner
Subsystem sftp sftp-server.exe
hostkeyagent \\.\pipe\openssh-ssh-agent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment