Search code examples
shellvisual-studio-codeamazon-ec2ssharm64

VSCode SSH Remote connected to EC2 instance, "shell integration failed to activate" for zsh based terminal


VSCode SSH Remote connected to AWS EC2 instance running Ubuntu 20.04 (ARM64)

I'm connecting to the instance using AWS SSM through the Remote SSH extension (see more detail about how here: https://github.com/aws/aws-toolkit-vscode/issues/941) which is working fine, but zsh shell integration fails with the message Shell integration failed to activate:

Launching a shell integrated zsh terminal

Resulting in the shell integration failed to activate error

Meanwhile, I can easily create a bash based terminal and write $ zsh afterwards:

Launching a shell integrated bash termnial

Resulting in working terminal

And manually entering zsh works as well

The is the output generated in the Log (Window) Output pane of VSCode:

[2022-08-09 19:22:35.667] [renderer1] [error] EPERM: operation not permitted, copyfile 
'/data/home/pens/.vscode-server/bin/da76f93349a72022ca4670c1b84860304616aaa2/out/vs/workbench/contrib/terminal/browser/media/shellIntegration-rc.zsh'
-> '/tmp/vscode-zsh/.zshrc':
Error: EPERM: operation not permitted, copyfile
'/data/home/pens/.vscode-server/bin/da76f93349a72022ca4670c1b84860304616aaa2/out/vs/workbench/contrib/terminal/browser/media/shellIntegration-rc.zsh'
-> '/tmp/vscode-zsh/.zshrc'

It prints a similar error for the following dot-files files: .zcompdump, .zlogin, .zprofile, .zshenv, .zshrc


Ultimately this means that the issue is related to access to the files in the directory: /tmp/vscode-zsh/

VSCode tries to create the 5 dot-files in the same folder with the same naming for the current user whenever it tries to launch a shell integrated zsh terminal. This results in permission denied / operation not permitted if the files have already been created for - and are owned by - another user.. Any ideas how to fix this?


Solution

  • This issue was caused by the 1.70 update of VSCode, an issue has been raised on the VSCode github: https://github.com/microsoft/vscode/issues/157611

    In the meantime the fix is to disable shellIntegration in your VSCode settings: "terminal.integrated.shellIntegration.enabled": false and add the following to your .zshrc:

    [[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"