VSCode에서 remote-SSH 사용하여 Linux to Windows 로 x11forward 시 launch.json 설정 방법

vision·2022년 12월 22일
0

remote: ubuntu18.04
local: windows 10

vscode remote-SSH 사용하여 remote에서 local로 x11forward를 하려고 했는데 아래와 같읕 에러가 발생했다.

qt.qpa.xcb: could not connect to display 
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/ubuntu/.local/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.

위 에러는 environment variable 중 DISPLAY 가 설정되지 않아서 화면을 출력할 x server 를 찾지 못했을 때 발생한다. qt 가 위와 같은 이유로 initialization 에 실패하여 발생한 것이다.

ssh 터미널에서 아래와 같이 설정 시 문제가 해결된다. export 는 server의 environment variable을 설정하는 command이다.

export DISPLAY=:10.0

위 설정을 매 실행(run) 시 마다 생성되는 터미널에 적용하고 싶은 경우 launch.json 을 아래와 같이 설정할 수 있다. 기본 설정에 "env" 부분을 추가한 것이다.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "test.py",
            "type": "python",
            "request": "launch",
            "program": "test.py",
            "console": "integratedTerminal",
            "justMyCode": true,
            "env":
            {
                "DISPLAY": "localhost:10.0"
            }
        }
    ]
}

DISPLAY 가 localhost:10.0 인 이유는 SSH server 가 client로부터 x11-req SSH request를 받으면 localhost:6010로부터 시작하는 X Server Proxy listen 를 열고 해당 SSH 세션의 $DISPLAY를 대응되는 소켓 localhost:10.0 으로 설정하기 때문이다.

출처: https://goteleport.com/blog/x11-forwarding/

0개의 댓글