windows 安装ssh server
win10
win10 版本更新后,本身携带了openssh client和openssh server
安装方法:
设置 -> 应用 -> 管理可选功能 -> 添加功能 -> “openssh 客户端” ”openssh 服务器"
问题记录:
- 无法安装成功
通过查看 “查看可选功能历史记录” 获取问题的详细信息 - 网络原因
需要将当前网络置于不收费网络中,否则安装失败
win7 & win8
此处推荐下载安装openssh powershell版本,简单方便
-
下载地址
下载最新版本,openssh-win64.zip
-
安装步骤
-
解压
将openssh-win64.zip解压到任意路径下,记:DESCOMPRESSION_PATH
(decompression path,解压缩路径) -
安装
在cmd
中进入到%DESCOMPRESSION_PATH%
路径中,输入#安装openssh server powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1 #将sshd服务设置为自启动 sc config sshd start= auto #启动sshd服务 net start sshd
-
修改配置文件
win中默认的配置文件在__PRAGRAMDATA__\ssh\ssh_config
文件中,__PRAGRAMDATA__
代指的路径是C:\ProgramData\
是一个隐藏文件夹端口号:Port 22
密钥访问:PubkeyAuthentication yes
密码访问:PasswordAuthentication no
空密码:PermitEmptyPasswords no -
无密码登录配置
新版本配置Administrator密钥配置文件不在.ssh/authorized_keys
中,变成了%programdata%\ssh\administrators_authorized_keys
文件中,
首先进入到%programdata%\ssh\
中,如果没有文件administrators_authorized_keys
, 首先创建,
再在cmd
中执行icacls administrators_authorized_keys /inheritance:r
icacls administrators_authorized_keys /grant SYSTEM:(F)
icacls administrators_authorized_keys /grant BUILTIN\Administrators:(F)修改ssh_config文件:
AuthorizedKeysFile %programdata%/ssh/administrators_authorized_keys
重启sshd服务即可
安装及使用问题记录
-
初次连接服务器时,需要进行验证
ssh -o StrictHostKeyChecking=no user@xxx.xxx.xxx.xxx
StrictHostKeyChecking
可以实现不需要输入yes/no
即可进入连接环节 -
使用ssh key文件,实现免密登录问题
首先使用ssh-keygen
生成密钥和公钥,详细方案参考:使用ssh实现免密登录ssh -i identity_file -o StrictHostKeyChecking=no user@xxx.xxx.xxx.xxx
identity_file
即为密钥 -
出现
connection reset by xxx.xxx.xxx.xxx port xx
,这时需要重新配置server,删除__PROGRAMDATA__\ssh
文件夹,重新启动sshd
服务即可