admin管理员组文章数量:1437831
takeown和icacls的配合使用
场景:Windows Cygwin环境,备份还原etc\ssh*.pub、etc\ssh*_key(合并的话是ssh_host_*key*)
备份:
代码语言:javascript代码运行次数:0运行复制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\
还原:
代码语言:javascript代码运行次数:0运行复制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启动报错如下,
代码语言:javascript代码运行次数:0运行复制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如下,确认是权限问题导致
代码语言:javascript代码运行次数:0运行复制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均可
代码语言:javascript代码运行次数:0运行复制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
代码语言:txt复制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'
本文标签: takeown和icacls的配合使用
版权声明:本文标题:takeown和icacls的配合使用 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/biancheng/1747540099a2703902.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论