下载 OpenSSH

OpenSSH 地址:https://github.com/PowerShell/Win32-OpenSSH/releases,选择同操作系统相同架构的 zip 包下载。
例如:OpenSSH-Win64.zip

安装

  1. 下载好包后解压并移动到 C:\Program Files 路径下。
  2. 添加 OpenSSH 路径(C:\Program Files\OpenSSH-Win64)到环境变量 Path 里。
  3. 安装sshd 服务
    执行 powershell 并移动到 OpenSSH 路径下。执行命令 .\install-sshd.ps1 安装 sshd 服务。
    PS > .\install-sshd.ps1
    [SC] SetServiceObjectSecurity 成功
    [SC] ChangeServiceConfig2 成功
    [SC] ChangeServiceConfig2 成功
    sshd and ssh-agent services successfully installed
    
  4. 生成 SSH 主机秘钥
    • 生成秘钥(无报错)
      PS > .\ssh-keygen.exe -A
      ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519
      
    • 如果生成秘钥时,报错如下:
      PS > .\ssh-keygen.exe -A
      ssh-keygen: generating new host keys: RSA Could not save your public key in __PROGRAMDAT__\\ssh/ssh_host_rsa_key.W5FfW3Crio: No such file or directory
      ssh-keygen: generating new host keys: DSA Could not save your public key in __PROGRAMDAT__\\ssh/ssh_host_dsa_key.q2dDCMGZU5: No such file or directory
      ssh-keygen: generating new host keys: ECDSA Could not save your public key in __PROGRAMDAT__\\ssh/ssh_host_ecdsa_key.6Hc8O5CjNo: No such file or directory
      ssh-keygen: generating new host keys: ED25519 Could not save your public key in __PROGRAMDAT__\\ssh/ssh_host_ed25519_key.nsSYd0vqdJ: No such file or directory
      

      则在 powershell 中执行如下命令

      PS > mkdir $env:ProgramData\ssh
      
          目录: C:\ProgramData
      
      Mode                LastwriteTime   Length Name
      ----                -------------   ------ ----
      d----           2020/3/15   16:58          ssh
      
      

      创建完目录后,再次执行命令 .\ssh-keygen.exe -A

      PS > .\ssh-keygen.exe -A
      ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519
      
  5. 启动 sshd 服务
    • services.msc 服务的图形界面找到 sshd 服务右键=>启动
    • 通过 powershell 命令启动
    PS > net start sshd
    OpenSSH SSH Server 服务正在启动 .
    OpenSSH SSH Server 服务已经启动成功。
    

标题:winServer 2012 R2 安装 OpenSSH
作者:akiya789
地址:https://little-star.love/articles/2020/03/15/1584261752814.html

添加新评论