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


问题背景:

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了。

以上


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM