Visual Studio Code Remote - SSH with sudo

How To use ssh with sudo in Visual Studio Code

Prepare custom ssh config

In home dir ~/.ssh/config copy to ~/.ssh/config_vscode:

1
cp ~/.ssh/config ~/.ssh/config_vscode

For work as differnet system user from sudo user workuser add remote command to ~/.ssh/config_vscode

MacOS or Linux

1
RemoteCommand sudo -u workuser -i

Full ssh config

1
2
3
4
5
6
Host srv01.internal
 HostName srv01.internal
 Port 22
 User srvuser
 IdentityFile ~/.ssh/id_ed25519
 RemoteCommand sudo -u workuser -i

Windows

1
2
RequestTTY yes
RemoteCommand sudo -u workuser -i

Full ssh config

1
2
3
4
5
6
7
Host srv01.internal
 HostName srv01.internal
 Port 22
 User srvuser
 IdentityFile ~/.ssh/id_ed25519
 RequestTTY yes
 RemoteCommand sudo -u workuser -i

Configure Visual Studio Code

Open Visual Studio Code user settings.json file, set custom ssh config and enableRemoteCommand to true.

1
2
"remote.SSH.configFile": "~/.ssh/config_vscode",
"remote.SSH.enableRemoteCommand": true,

Check defaultSettings.json is set useLocalServer to true

1
"remote.SSH.useLocalServer": true,

Connect to host as sudo user

In Visual Studio Code open Connect to host: Remote-SSH with preconfigured ssh host srv01.internal

Licensed under CC BY-NC-SA 4.0
Last updated on Sep 22, 2025 18:14 MSK