联系:手机/微信(+86 17813235971) QQ(107644445)
作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]
在某些情况下,需要在win环境中安装ssh,sftp等服务,可以考虑通过安装OpenSSH,下载地址:https://github.com/PowerShell/Win32-OpenSSH/releases,下载最新版OpenSSH-Win64.zip并解压
openssh安装服务
Microsoft Windows [版本 10.0.19045.3208] (c) Microsoft Corporation。保留所有权利。 C:\Windows\system32>cd E:\OpenSSH-Win64 C:\Windows\system32>e: E:\OpenSSH-Win64>powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1 [*] E:\OpenSSH-Win64\moduli Inheritance is removed from 'E:\OpenSSH-Win64\moduli'. 'NT AUTHORITY\Authenticated Users' now has Read access to 'E:\OpenSSH-Win64\moduli'. 'BUILTIN\Users' now has Read access to 'E:\OpenSSH-Win64\moduli'. Repaired permissions [*] C:\ProgramData\ssh looks good [SC] SetServiceObjectSecurity 成功 [SC] ChangeServiceConfig2 成功 [SC] ChangeServiceConfig2 成功 sshd and ssh-agent services successfully installed Updated Machine PATH to include OpenSSH directory, restart/re-login required to take effect globally E:\OpenSSH-Win64>net start sshd OpenSSH SSH Server 服务正在启动 .. OpenSSH SSH Server 服务已经启动成功。 E:\OpenSSH-Win64>ssh -V OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2
也可以可以通过cmd命令设置:sc config sshd start= auto
配置免密登录
1)修改C:\ProgramData\ssh\ssh_config文件
PubkeyAuthentication yes AuthorizedKeysFile %programdata%/ssh/administrators_authorized_keys
2)拷贝C:\ProgramData\ssh\ssh_host_rsa_key为C:\ProgramData\ssh\administrators_authorized_keys
3)下载ssh_host_rsa_key和ssh_host_rsa_key.pub文件,放到其他机器的C:\Users\用户名\.ssh目录中并重命名为id_rsa和id_rsa.pub
测试其他机器免密ssh/sftp登录
C:\Users\XFF>ssh xifenfei@192.168.222.2 Microsoft Windows [版本 10.0.19045.3208] (c) Microsoft Corporation。保留所有权利。 xifenfei@DESKTOP-3PQ0P6C C:\Users\xifenfei>exit Connection to 192.168.222.2 closed. C:\Users\XFF>sftp xifenfei@192.168.222.2 Connected to 192.168.222.2. sftp> pwd Remote working directory: /C:/Users/xifenfei