简体   繁体   English

在 WSL2 中使用 VSCode 连接 SSH?

[英]Connecting with SSH using VSCode inside WSL2?

I'm trying to SSH connect to an EC2 instance inside of VSCode, but I keep getting this error:我正在尝试 SSH 连接到 VSCode 内的 EC2 实例,但我不断收到此错误:

https://i.imgur.com/StIQ6Uh.jpg https://i.imgur.com/StIQ6Uh.jpg

It says my pem file is "too open" and "not protected" so it's denying access.它说我的 pem 文件“太开放”和“未受保护”,所以它拒绝访问。


My issue is I already used this pem file as a key to a different instance and it worked fine.我的问题是我已经使用这个 pem 文件作为另一个实例的密钥并且它工作正常。 I already ran "chmod 400 swayek.pem" a few days ago and it worked.几天前我已经运行了“chmod 400 swayek.pem”并且它起作用了。

I tried running it again multiple times:我尝试多次再次运行它:

https://i.imgur.com/586e88J.jpg https://i.imgur.com/586e88J.jpg

but I'm still not able to connect.但我仍然无法连接。

BUT it works and connects when not using VScode.但是在不使用 VScode 时它可以工作并连接。 This actually connects fine:这实际上连接得很好:

ssh -i swayek.pem ec2-user@ec2-44-212-10-54.compute-1.amazonaws.com

https://i.imgur.com/0BuJUqG.png https://i.imgur.com/0BuJUqG.png


I think WSL2 is causing the problem because my SSH key is in the WSL2 distro side and VSCode isn't connected to the WSL distro when running SSH.我认为 WSL2 导致了问题,因为我的 SSH 密钥在 WSL2 发行版端,而 VSCode 在运行 SSH 时未连接到 WSL 发行版。

Normally I'm connected to Ubuntu like this:通常我像这样连接到 Ubuntu:

https://i.imgur.com/NBT60FJ.png https://i.imgur.com/NBT60FJ.png

but it doesn't allow you to open SSH from inside a Ubuntu container.但它不允许您从 Ubuntu 容器内部打开 SSH。 It always opens a new window and connects to SSH from the default windows terminal.它总是打开一个新的 window 并从默认的 windows 终端连接到 SSH。 I'm not 100% sure but I think that's the problem.我不是 100% 确定,但我认为这就是问题所在。

Does anybody with more knowledge know what the issue is here and how to fix it?有更多知识的人知道这里的问题是什么以及如何解决吗?


EDIT:编辑:

I figured I would just try to copy the "swayek.pem" file over to the windows side and set the permissions on that.我想我会尝试将“swayek.pem”文件复制到 windows 端并设置权限。

I followed this [Github post][1] as the Windows equivalent to "chmod 400":我按照这个 [Github post][1] 作为 Windows 相当于“chmod 400”:

# Source: https://stackoverflow.com/a/43317244
$path = ".\aws-ec2-key.pem"
# Reset to remove explict permissions
icacls.exe $path /reset
# Give current user explicit read-permission
icacls.exe $path /GRANT:R "$($env:USERNAME):(R)"
# Disable inheritance and remove inherited permissions
icacls.exe $path /inheritance:r

https://i.imgur.com/ZMxvZLv.jpg https://i.imgur.com/ZMxvZLv.jpg

But now I'm getting a DIFFERENT error and I dont understand it.但是现在我遇到了一个不同的错误,我不明白。 Can anyone decipher this error?谁能破译这个错误?

https://i.imgur.com/ojZFkdQ.jpg https://i.imgur.com/ojZFkdQ.jpg

In my Remote Settings I have在我的远程设置中,我有

"terminal.integrated.profiles.linux": {

    "zsh": {
        "path": "zsh",
        "args": [ "-l" ]
    },
    "bash": null,
    "tmux": null,
    "JavaScript Debug Terminal": null
},

Then I create a new zsh terminal and can SSH from there without issue.然后我创建了一个新的zsh终端,并且可以从那里毫无问题地访问 SSH。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM