How To ssh unter Windows mit WSL2 und Laufwerks-Montieren

Um was geht es:
  • empfohlene ssh-Keys
  • Autostart für Putty Agent
  • so dass der Agent auch für Windows OpenSSH und WSL2 nutzbar ist
  • sftp-Konto per rclone als Laufwerk einbinden

PuTTY installieren

ssh Private key generieren

  • "C:\Program Files\PuTTY\puttygen.exe"
  • ECDSA auswählen (alternativ noch EdDSA, aber RSA ist definitiv deprecated!!!)
  • "Generate"
  • "Key comment" auf einen Sinnvollen Namen ändern, z.B. J.Petersen@2026 o.ä.
  • "Key Passphrase" bitte undbedingt definieren, damit niemand fremdes Euren Key missbrauchen kann
  • "Save Private Key"
    Speichern unter %USERPROFILE%\.ssh\MeinSshKey.priv.ppk
    Bei mir C:\Users\jp\.ssh\jp.2024.priv.ppk
  • Den Public Key am Zielsystem hinterlegen, vgl. auch https://gitlab.com/msh-gmbh/mit/server/sshkeys für zentrale Doku

Vorbereiten für Windows-natives ssh zusätzlich zu PuTTY

Ziel: den Private Key über den Agenten auch mit dem WIndows-Bordmittel-ssh verwenden zu können
  • CMD
  • mkdir %USERPROFILE%\.ssh
  • notepad %USERPROFILE%\.ssh\config
  • Inhalt der Datei:
    Include pageant.conf

Autostart des pagent mit dem Private Key

  • "WindowsTaste" + "R" oder Windows-Menüpukt "Ausführen"
    shell:startup
    (öffnet bei mir Verszeichnis C:\Users\jp\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup)
  • Neue Datei anlegen:
    pagent.cmd
  • mit Editor bearbeiten
  • Inhalt:
    ("MeinSshKey" auf Deinen richtigen Dateinamen anpassen!)

    START /B pageant --openssh-config %USERPROFILE%\.ssh\pageant.conf %USERPROFILE%\.ssh\MeinSshKey.priv.ppk
    
    rem hier mit Beispiel rclone Aufruf für Laufwerks-montieren
    timeout /t 20 
    START /B rclone mount --vfs-cache-mode=full --buffer-size=16M --vfs-read-ahead=64M mshsupp1:/home/u/jp H:\

sftp Zugang als Laufwerk montieren

  • CMD
  • winget install -e --id Rclone.Rclone
  • Hier Beispiel Leitstand ("mshsupp1") Home-Verzeichnis Jörg (user jp)
  • notepad %USERPROFILE%\AppData\Roaming\rclone\rclone.conf
  • Inhalt:
    [mshsupp1]
    type = sftp
    host = mshsupp1
    user = jp
    key_use_agent = true
    shell_type = unix
    md5sum_command = md5sum
    sha1sum_command = sha1sum
    vfs-cache-mode = full
    buffer-size = 16M
    vfs-read-ahead = 64M

Agent Forwarding erlauben

Putty-Config-Agent-Forwarding.jpg

Agent in WSL-2 verwenden

Setup in Windows:
  • Download wsl2-ssh-pageant.exe von https://github.com/BlackReloaded/wsl2-ssh-pageant/releases/latest/download/wsl2-ssh-pageant.exe
  • Abspeichern unter %USERPROFILE%\wsl2-ssh-pageant.exe (bei mir in c:\users\jp\)
  • CMD
  • "WindowsTaste" + "R" oder Windows-Menüpukt "Ausführen"
    shell:startup
    (öffnet bei mir Verszeichnis C:\Users\jp\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup)
  • Neue Datei anlegen:
    run-wsl-ssh.cmd
  • mit Editor bearbeiten
  • Inhalt:
    start /b %USERPROFILE%\wsl2-ssh-pageant.exe --wsl %USERPROFILE%\ssh-agent.sock
Setup In Linux unter WSL2
  • bash / WSL2 aufrufen
  • Im folgenden Pfade / User bitte anpassen (jp bzw. /mnt/c/Users)
  • windows_destination="/mnt/c/Users/jp/wsl2-ssh-pageant.exe" 
    linux_destination="$HOME/.ssh/wsl2-ssh-pageant.exe" 
    # wurde schon oben bei "Setup in Windows" gemacht
    # wget -O "$windows_destination" "https://github.com/BlackReloaded/wsl2-ssh-pageant/releases/latest/download/wsl2-ssh-pageant.exe" 
    # Set the executable bit. 
    chmod +x "$windows_destination" 
    # Symlink to linux for ease of use later 
    ln -s $windows_destination $linux_destination
  • Die .bashrc erweitern. Hier als Refenz meine:
    jp@mshl80656:~$ cat .bashrc
    echo "Dies ist .bashrc"
    cd ~
    export BROWSER='/mnt/c/Program Files/Mozilla Firefox/firefox.exe'
    update_clock () {
            echo '[ROOT] Updating clock'
            sudo ntpdate time.windows.com
    }
    update_clock
    ############
    # siehe https://github.com/BlackReloaded/wsl2-ssh-pageant
    ############
    export SSH_AUTH_SOCK="$HOME/.ssh/agent.sock"
    if ! ss -a | grep -q "$SSH_AUTH_SOCK"; then
      rm -f "$SSH_AUTH_SOCK"
      wsl2_ssh_pageant_bin="$HOME/.ssh/wsl2-ssh-pageant.exe"
      if test -x "$wsl2_ssh_pageant_bin"; then
        (setsid nohup socat UNIX-LISTEN:"$SSH_AUTH_SOCK,fork" EXEC:"$wsl2_ssh_pageant_bin" >/dev/null 2>&1 &)
      else
        echo >&2 "WARNING: $wsl2_ssh_pageant_bin is not executable."
      fi
      unset wsl2_ssh_pageant_bin
    fi
    export PATH="$HOME/.local/bin:$PATH"
    alias py=~/aws-python/bin/python
    alias ll="ls -l"
Topic revision: r1 - 17 Apr 2026, JoergPetersen
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback