win10 vscode Remote-SSH:解决Bad owner or permissions问题

时光毁灭记忆、已成空白 提交于 2019-12-02 21:45:15

问题背景:

vscode的Remote-SSH扩展一直工作正常,但是在某次win10系统更新后,Remote-SSH扩展突然无法工作,控制台log显示错误为“Bad owner or permissions”。

错误内容分析:

“Bad owner or permissions”表示对某个文件没有操作权限,经确认,原因为win10自带的openssh客户端的权限存在异常,需进行权限修复。

错误修复流程:

经过一番查找,在vscode官方文档里找到了解决方案,如下所示:

Windows:

The specific expected permissions can vary depending on the exact SSH implementation you are using. We strongly recommend using the out of box Windows 10 OpenSSH Client. If you are using this official client, cut-and-paste the following in an administrator PowerShell window to try to repair your permissions:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process

Install-Module -Force OpenSSHUtils -Scope AllUsers

Repair-UserSshConfigPermission ~/.ssh/config
Get-ChildItem ~\.ssh\* -Include "id_rsa","id_dsa" -ErrorAction SilentlyContinue | % {
    Repair-UserKeyPermission -FilePath $_.FullName @psBoundParameters
}

但是,上述代码无法正常运行,“Install-Module -Force OpenSSHUtils -Scope AllUsers”命令运行会报错,显示安装包校验码错误。

下面将提供一种方法解决命令运行报错问题:

步骤1:前往https://github.com/PowerShell/Win32-OpenSSH/releases下载最新的OpenSSH-Win64.zip,解压后得到如下所示文件

 

 

 步骤2:安装OpenSSHUtils模块

import-Module G:\OpenSSH-Win64\OpenSSHUtils.psm1

 

请将模块安装包路径替换为你的本地路径。

综上所述,最终有效的命令组合为:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
import-Module G:\OpenSSH-Win64\OpenSSHUtils.psm1

Repair-UserSshConfigPermission ~/.ssh/config
Get-ChildItem ~\.ssh\* -Include "id_rsa","id_dsa" -ErrorAction SilentlyContinue | % {
    Repair-UserKeyPermission -FilePath $_.FullName @psBoundParameters
}

 

修复完成后,就可继续正常使用Remote-SSH了。

以上

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!