windows 上 OpenSSH 服务 启用秘钥登录(微软真心逆天)

windows 安装 OpenSSH 服务

最近需要在windows 服务器上部署自动发布程序,那么就需要用到 scp 和 ssh 的免密登录了

首先需要安装 OpenSSH 服务,过程可以看我上篇

windows 创建秘钥

定位到 C:\Program Files\OpenSSH,启用 powershell

cd 'C:\Program Files\OpenSSH'

$ .\ssh-keygen  <== 建立密钥对
Generating public/private rsa key pair. ...
一路enter

定位到 C:\Users\Administrator.ssh 生成 authorized_keys 文件

cd C:\Users\Administrator\.ssh
cat id_rsa.pub >> authorized_keys

到这里你以为就可以像linux一样使用秘钥登录了?

不你错了!!! 这坑了我好长时间,我以为是权限问题,后来Google发现 微软真心坑爹

解决办法如下

找到 C:\ProgramData\ssh 文件夹中的 sshd_config

看看最后一行!!

# override default of no subsystems
Subsystem sftp sftp-server.exe # Example of overriding settings on a per-user basis
#Match User anoncvs
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server Match Group administrators
AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

这啥意思呢? 就是刚刚生成的authorized_keys 文件要放在 C:\ProgramData\ssh 文件夹下,还要改名成 administrators_authorized_keys !!!

执行 cat id_rsa.pub >> administrators_authorized_keys

还有就是修改ssh 配置也是在 sshd_config 里面!

修改 sshd_config

完整配置

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information. # The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value. #Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress :: #HostKey __PROGRAMDATA__/ssh/ssh_host_rsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_dsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ecdsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ed25519_key # Ciphers and keying
#RekeyLimit default none # Logging
#SyslogFacility AUTH
#LogLevel INFO # Authentication: #LoginGraceTime 2m RSAAuthentication yes
PubkeyAuthentication yes
PermitRootLogin yes #PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10 #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 #AuthorizedPrincipalsFile none # For this to work you will also need host keys in %programData%/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes # To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no # GSSAPI options
#GSSAPIAuthentication no #AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none # no default banner path
#Banner none # override default of no subsystems
Subsystem sftp sftp-server.exe # Example of overriding settings on a per-user basis
#Match User anoncvs
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server Match Group administrators
AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

与原配置相比增加三行

RSAAuthentication yes # 允许rsa
PubkeyAuthentication yes # 允许公钥登录
PermitRootLogin yes # 允许root登录



好吧 我照做

复制 id_rsa 到 linux 文件夹下 , chmod 600 id_rsa 设置 权限

ssh 登录

ssh -i ~/.ssh/keys/118.190.102.245/id_rsa Administrator@118.190.102.245

好吧 我照做,成功了 ...

windows 上 OpenSSH 服务 启用秘钥登录(微软真心逆天)的更多相关文章

  1. windows上OpenSSH服务安装及启动

    一.windows安装OpenSSH 1,下载openSSH windows版 GitHub下载链接 我安装的是64位版本 OpenSSH-Win64.zip 2,解压到C:\Program File ...

  2. 腾讯云服务器,使用xshell ssh秘钥登录的时候报错:所选的用户密钥未在远程主机上注册

    1.背景 新买了台腾讯云服务器,在腾讯云控制台新建了SSH私钥,然后下载到本地. 在本地使用xshell工具,导入下载好的私钥进行登录,报错:所选的用户密钥未在远程主机上注册 2.解决方案 在确定选择 ...

  3. SSH设置秘钥登录

    设置 SSH 通过密钥登录 我们一般使用 PuTTY 等 SSH 客户端来远程管理 Linux 服务器.但是,一般的密码方式登录,容易有密码被暴力破解的问题.所以,一般我们会将 SSH 的端口设置为默 ...

  4. SSH配置免秘钥登录

    一.  SSH 配置免秘要登录 配置SSH 免秘要登录,虽然就那么几步,但总是会出现点小问题,今天就做下记录.SSH 免秘钥就是让两台机器相互信任,不需要输入密码就能相互登录.配置相互信任就是把各自的 ...

  5. linux秘钥登录

    秘钥登录首先要了解四个文件: 公钥文件,私钥文件, authorized_keys, 还有/etc/ssh/sshd_config配置文件. 公钥文件存放在被登陆的机器上, 要将公钥添加进author ...

  6. 非对称加密 秘钥登录 https

    非对称加密简介: 对称加密算法在加密和解密时使用的是同一个秘钥:而非对称加密算法需要两个密钥来进行加密和解密,这两个秘钥是公开密钥(public key,简称公钥)私有密钥(private key,简 ...

  7. Windows安装OpenSSH服务

    一.背景 在做国盛通项目的时候,有两套并行测试环境,因为基本架构采用的是供应商提供的程序,需要将两套banner图做同步,因为图片数量多,进GitLab版本控制进行分支策略管理,进而同步两套环境,意义 ...

  8. linux使用秘钥登录(禁用root密码登录)

    目的:为了巩固线上外网服务器的安全,避免黑客攻击植入木马,初步决定禁用root密码登录(安全强度低),统一使用秘钥登录(4096位长度,安全性较高) 具体操作如下: 一.生成ssh秘钥: ssh-ke ...

  9. ssh设置免秘钥登录

    系统:CentOS7.2 需求:A服务器的fab用户需要使用www用户免秘钥登录到B服务器 换句话说,就是在A服务器的fab用户下,ssh    www@B服务ip   -p  端口  ,然后登录过去 ...

随机推荐

  1. Python自动扫描出微信不是好友名单

    前言 最近找几个老友准备聊天发现几个已经被删除好友名单,做为潜水党多年的我已经不知道成为多少人的黑名单,但是好友列表却依然有不是好友的名单,面对庞大的好友数量想要清除谈何容易.虽然可以发消息给所有人, ...

  2. CRM系统实施中如何避免“踩雷”

    CRM系统实施后,效果没有达到预期是很多企业出现的情况.而最主要的原因就是在实施之前没有足够的思考和相应的计划.那么,企业应如何避免CRM系统实施时"踩雷"?这里有几条建议希望可以 ...

  3. [基本运算符、流程控制之if判断、与用户交互、深浅拷贝]

    [基本运算符.流程控制之if判断.与用户交互] 基本运算符 1.算数运算符 python支持的算术运算符与数学上计算的符号使用是一致的 salary = 3.3 res = salary * 12 p ...

  4. CentOS7 / CentOS8 设置终端屏幕分辨率

    Centos7 修改文件 /boot/grub2/grub.cfg 搜索 linux16 / /vmlinuz-3.10.0-123.el7.x86_64 root=UUID=881ac4e6-4a5 ...

  5. [前端] JSON

    背景 JavaScript对象表示法(JavaScript Object Notation):是一种存储数据的方式 JSON对象 创建 var gareen = {"name":& ...

  6. Debian 9.4 多网卡链路聚合bond配置

    Debian 9.4 多网卡链路聚合bond配置 安装ifenslave ifenslave 的作用是网卡的负载均衡 root@debian:~# apt-get install ifenslave ...

  7. xpath元素定位语法

    举个栗子 -------------------------------------------------------------------------------------- <?xml ...

  8. jmeter 非GUI模式下传参

    为什么要使用非GUI模式?--因为GUI模式下运行的时候消耗的内存比非GUI模式大,会使得压力测试的结果不准确. 根据参数类型分为两种:jmeter.properties和system.propert ...

  9. zabbix监控之自动发现/自动注册

    一.自动发现 1.概述 自动发现(LLD)提供了一种在计算机上为不同实体自动创建监控项,触发器和图形的方法.例如,zabbix可以在你的机器上自动开始监控文件系统或者网络接口,而无需为每个文件系统或网 ...

  10. 03丨认识文档数据库MongoDB