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