14

How do the change the shell used for VS Code's integrated terminal when I connect to an remote ssh workspace?

Matt Bierner
  • 58,117
  • 21
  • 175
  • 206

3 Answers3

15

Adding to @Matt Bierner's answer.

The newer versions of vscode now lets you set up profiles for your terminal and give them your custom name and that name is supposed to be referenced in your remote settings.

CTRL+SHIFT+P -> Preferences: Open Settings (JSON)

user configs

...
"terminal.integrated.profiles.linux": {
    "s-mann-term": {
        "path": "/usr/bin/zsh"
    },
    "bash": {
        "path": "bash"
    },
    "zsh": {
        "path": "zsh"
    },
    "my-fav-term": {
        "path": "fish"
    }
},
"terminal.integrated.defaultProfile.linux": "s-mann-term"
...

This will make all hosts to default to /usr/bin/zsh (I just used path key in my profile but there are bunch of other options that you can modify)

NOTE: You can add multiple profiles for the same shell as well. For example, 5 differently configured zsh profiles.

CTRL+SHIFT+P -> Preferences: Open Remote Settings (SSH: az-box1)

az-box1 configs

...
"terminal.integrated.defaultProfile.linux": "my-fav-term"
...

But az-box1 will default to fish

Sukhinderpal Mann
  • 744
  • 1
  • 10
  • 23
  • 2
    For the newer versions of vscode, this answer is the right answer!. Thanks – Dvir Itzko Sep 01 '21 at 16:27
  • Can you clarify why you have `/usr/bin/zsh` for s-mann-term and just `zsh` for zsh profiles? – j7skov Jul 25 '22 at 14:26
  • I am asking because if I use `terminal.integrated.shell.linux` in my remote settings.json it works, but this solution (above) does not. – j7skov Jul 25 '22 at 14:44
13

You can use remote setting to change the shell for each host. To do this, open the remote workspace in VS Code and run the Open Remote settings command:

The Open Remote Settings commands

Set terminal.integrated.shell.linux to point to your shell and save the file:

"terminal.integrated.shell.linux": "/usr/bin/fish"

enter image description here

The remote settings apply to all workspaces you open on a given host, but must be configured for each host you connect to.

Matt Bierner
  • 58,117
  • 21
  • 175
  • 206
1

None of the above answers worked for me and I've been trying to get the default shell to be zsh for many months. What finally worked was adding the following to the top of my .bashrc:

if [[ "$TERM_PROGRAM" == "vscode" ]]; then
  # ~/.profile is run by the login shell (this is what ssh uses)
  # ~/.bashrc is run by the interactive shell (this is what vscode uses)
  # Therefore, we only need to change the shell to zsh here since
  # vscode will run ~/.bashrc for us.
  exec zsh -l
fi
Eric Wiener
  • 4,929
  • 4
  • 31
  • 40
  • Where does TERM_PROGRAM come from? I'm not seeing it set when connecting to a windows machine with the OpenSSH service running and its shell set to `C:/program files/git/bin/bash.exe` – jozxyqk Jun 26 '23 at 19:00