Dhr*_*orz 15 ssh visual-studio-code vscode-remote
我在windows 10上使用WSL进行编程,最近发现可以使用VS code通过SSH编辑程序。
但是,我通常通过 WSL SSH 进入我大学的计算机,以便我可以访问这些系统上的文件并使用它们的 GPU。
有什么方法可以使用 vscode SSH 进入 WSL,然后 ssh 进入我的大学系统,并可以从 vscode 中访问他们的资源和文件系统?
Haz*_*d17 21
您可以ssh.bat在Windows下创建文件,内容如下:
C:\\Windows\\system32\\wsl.exe ssh %*\nRun Code Online (Sandbox Code Playgroud)\n然后将 VS Code 设置“remote.SSH.path”设置为指向该 bat 文件。
\n您\xe2\x80\x99 将在 VS Code 中拥有与 WSL 中相同的 ssh 配置和凭据。
小智 6
如果写入C:\Windows\system32\wsl.exe ssh %*文件ssh.bat大部分有效,但会出现问题,而您的文件~/.bashrc来源不明,请将命令替换为
C:\Windows\system32\wsl.exe bash -ic 'ssh %*'
Run Code Online (Sandbox Code Playgroud)
此调整ssh在交互式 bash shell 中运行命令,该 shell 会获取您的~/.bashrc. 使用上述解决了 Ubuntussh-agent未在 VSCode 远程终端上转发密钥的问题。
小智 5
要从在 VScode 中运行的 WSL 连接到 Linux 计算机,我执行了以下操作:
Host <your_host>
HostName <your_host>
User <your_username>
IdentityFile C:\Users\<your_username>\.ssh\<your_private_key>
Run Code Online (Sandbox Code Playgroud)
Host <your_host>
HostName <your_host>
User <your_username>
IdentityFile C:\Users\<your_username>\.ssh\<your_private_key>
Run Code Online (Sandbox Code Playgroud)
如果您可以从 WSL 通过 SSH 访问大学系统,我假设您可以直接从 Windows 系统通过 SSH 访问。在这种情况下,您可以从 Windows 设置 VS Code 远程 SSH 来直接访问您的大学系统。鉴于此,我使用了 Git Bash 终端,因为它直接支持 Windows 操作系统中的所有 Linux 命令。
\n\n第 1 步:设置对大学系统的 SSH 访问(无密码或无密码)。您可以在线参考文章,我假设您已经知道如何做到这一点,因为您是在 WSL 中完成的。
\n\n步骤2:在本地机器的VS Code扩展中安装远程开发包。
\n\n步骤 3:转到 VS Code 设置并展开扩展下拉列表并选择“远程 - SSH”。在设置页面上,将“远程 - SSH:配置文件”设置为用于存储远程系统详细信息的 ssh 配置文件。例如:~\\vscode.ssh\n同时选中 \xe2\x80\x98 始终显示 SSH 终端\xe2\x80\x99 的复选框。
\n\n步骤 4:将远程系统详细信息添加到文件 ~\\vscode.ssh 中,如下所示:
\n\nHost <hostname>\n User <ID for SSH login> # e.g. your university ID\n HostName <full qualified address for your remote system> # e.g. system.subnet.university.edu\n IdentityFile <your SSH pvt key> #e.g. ~/.ssh/id_rsa\nRun Code Online (Sandbox Code Playgroud)\n\n第 5 步:选择左侧导航栏上的远程资源管理器,然后从下拉列表中选择“SSH 目标”。您的主机名应该出现在这里。右键单击并连接到主机。
\n\n步骤 6:如果提取 tar 文件失败,请仔细观察 VSCode 终端日志中第一次连接尝试的日志。
\n\n默认情况下,VS Code 将 vscode-server 安装在远程系统的主目录中,根据您所在大学的空间限制,该目录可能会出现空间不足的情况。您需要将 vscode-server 目录移动到空间限制较少的工作区域,通常是项目区域。使用以下步骤来执行此操作,我创建了这些供我的组织使用:
\n\n远程启动 VSCode 后,连接可能会失败或成功,具体取决于远程主目录中的可用空间,默认情况下,VSCode 在主目录中设置远程服务器,并且无法更改。
\n\n如果成功,仍然将 vscode-server 移动到另一个大的可用空间目录:
\n\na. Navigate to a desired project space directory from remote desktop terminal\nb. mv ~/.vscode-server /your/big/disk/project/space\nc. ln -s /your/big/disk/project/space/.vscode-server ~/.vscode-server\nd. Use full absolute paths in previous command to avoid cyclic links. Confirm with below command, it shoud not return anything.\n $ find -L ./ -mindepth 15\ne. Reconnect from your VSCode again\nRun Code Online (Sandbox Code Playgroud)如果失败,请在远程大可用空间目录上手动设置 vscode-server:
\n\na. Get vscode-server commit ID on remote server using below command, which would be like \'e2d4cc38bb5da82wb67q86fd50f84h67bb340987\'\n $ ls ~/.vscode-server/bin\nb. Download tarball replacing $COMMIT_ID with the the commit number from the previous step on local system: https://update.code.visualstudio.com/commit:$COMMIT_ID/server-linux-x64/stable\nc. Move tarball to remote server disk from local system:\n $ scp -P 22 vscode-server-linux-x64.tar.gz remoteID.remote.system.url.com:~/\nd. Move tarball to large free space directory as below:\n $ mkdir -p /your/big/disk/project/space/.vscode-server/bin/$COMMIT_ID/\n $ mv\xc2\xa0~/vscode-server-linux-x64.tar.gz /your/big/disk/project/space/.vscode-server/bin/$COMMIT_ID/\ne. Extract tarball in this directory\n $ cd /your/big/disk/project/space/.vscode-server/bin/$COMMIT_ID\n $ tar -xvzf vscode-server-linux-x64.tar.gz --strip-components 1\nf. Create symlink of .vscode-server in your home directory\n $ ln -s /your/big/disk/project/space/.vscode-server ~/.vscode-server\ng. Connect again\nRun Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
4556 次 |
| 最近记录: |