场景:Windows Cygwin环境,备份还原etc\ssh*.pub、etc\ssh*_key(合并的话是ssh_host_*key*)
备份:
takeown /F "C:\cygwinroot\etc\ssh*.pub" /A /R /D Y
icacls "C:\cygwinroot\etc\ssh*.pub" /grant:r "Administrator:(F)" /T /C /Q
Xcopy /F /H /Y C:\cygwinroot\etc\ssh*.pub C:\keypub\
takeown /F "C:\cygwinroot\etc\ssh*_key" /A /R /D Y
icacls "C:\cygwinroot\etc\ssh*_key" /grant:r "Administrator:(F)" /T /C /Q
Xcopy /F /H /Y C:\cygwinroot\etc\ssh*_key C:\keypub\
还原:
takeown /F "C:\cygwinroot\etc\ssh*.pub" /A /R /D Y
icacls "C:\cygwinroot\etc\ssh*.pub" /grant:r "Administrator:(F)" /T /C /Q
takeown /F "C:\cygwinroot\etc\ssh*_key" /A /R /D Y
icacls "C:\cygwinroot\etc\ssh*_key" /grant:r "Administrator:(F)" /T /C /Q
Xcopy /F /H /Y C:\keypub\ssh*.pub c:\cygwinroot\etc\
Xcopy /F /H /Y C:\keypub\ssh*_key c:\cygwinroot\etc\
如果cygwin sshd启动报错如下,
PS C:\Users\Administrator>net start sshd
CYGWIN sshd 服务正在启动 .
CYGWIN sshd 服务无法启动。
服务没有报告任何错误。
请键入 NET HELPMSG 3534 以获得更多的帮助。
PS C:\Users\Administrator> NET HELPMSG 3534
服务没有报告任何错误。
则查看C:\cygwinroot\var\log\sshd.log如下,确认是权限问题导致
Permissions 0070 for '/etc/ssh_host_rsa_key' are too open.
Permissions 0070 for '/etc/ssh_host_dsa_key' are too open.
Permissions 0070 for '/etc/ssh_host_ecdsa_key' are too open.
Permissions 0070 for '/etc/ssh_host_ed25519_key' are too open.
解决方案:提权Administrator后启动sshd服务
cmd、powershell均可
takeown /F "C:\cygwinroot\etc\ssh*.pub" /A /R /D Y
icacls "C:\cygwinroot\etc\ssh*.pub" /grant:r "Administrator:(F)" /T /C /Q
takeown /F "C:\cygwinroot\etc\ssh*_key" /A /R /D Y
icacls "C:\cygwinroot\etc\ssh*_key" /grant:r "Administrator:(F)" /T /C /Q
或者调整通配符合并为2句
takeown /F "C:\cygwinroot\etc\ssh_host_*key*" /A /R /D Y
icacls "C:\cygwinroot\etc\ssh_host_*key*" /grant:r "Administrator:(F)" /T /C /Q
仅powershell
cmd.exe /c 'takeown /F "C:\cygwinroot\etc\ssh*.pub" /A /R /D Y'
cmd.exe /c 'icacls "C:\cygwinroot\etc\ssh*.pub" /grant:r "Administrator:(F)" /T /C /Q'
cmd.exe /c 'takeown /F "C:\cygwinroot\etc\ssh*_key" /A /R /D Y'
cmd.exe /c 'icacls "C:\cygwinroot\etc\ssh*_key" /grant:r "Administrator:(F)" /T /C /Q'
或者调整通配符合并为2句
cmd.exe /c 'takeown /F "C:\cygwinroot\etc\ssh_host_*key*" /A /R /D Y'
cmd.exe /c 'icacls "C:\cygwinroot\etc\ssh_host_*key*" /grant:r "Administrator:(F)" /T /C /Q'
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有