Repository: microsoft/vscode (TypeScript)
Date: 2022-08-31 13:25:03+00:00
Task type: Bug Fix

Issue:
The terminal cannot be opened when multiple users use remote-ssh

Type: <b>Bug</b>

The terminal cannot be opened when multiple users use remote-ssh

When I used Remote-SSH today, I found that the terminal could not be opened. After checking the log, I found the following error output:

```
[2022-08-09 15:52:42.302] [remoteagent] [error] ["Error: EACCES: permission denied, copyfile '/home/{myuser}/.vscode-server/bin/da76f93349a72022ca4670c1b84860304616aaa2/out/vs/workbench/contrib/terminal/browser/media/shellIntegration-rc.zsh' -> '/tmp/vscode-zsh/.zshrc'"]
```

Since the terminal I use is `zsh`, vscode-server copies my  `.zshrc` to `/tmp/vscode-zsh/.zshrc`, and the permission of this file belongs to me. As a result, the other users who use `zsh` as the terminal cannot open the terminal when using Remote-SSH for no permission to overwrite this file.

And I find that when the user uses bash, vscode-server does not copy `.bashrc` to `/tmp/vscode-bash/.bashrc`. Therefore, this bug does not exist when `bash` is used by all users
 

VS Code version: Code 1.70.0 (da76f93349a72022ca4670c1b84860304616aaa2, 2022-08-04T04:38:55.829Z)
OS version: Darwin x64 20.6.0
Modes:
Remote OS version: Linux x64 5.4.0-122-generic
Remote OS version: Linux x64 5.4.0-122-generic

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz (12 x 3700)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: disabled_off<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>metal: disabled_off<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_renderer: enabled_on<br>video_decode: enabled<br>video_encode: enabled<br>webgl: enabled<br>webgl2: enabled|
|Load (avg)|3, 3, 3|
|Memory (System)|16.00GB (0.33GB free)|
|Process Argv|--crash-reporter-id 7fae5c7a-b061-4e88-926b-c65a9268e173|
|Screen Reader|no|
|VM|0%|

|Item|Value|
|---|---|
|Remote|SSH: 10.12.41.222|
|OS|Linux x64 5.4.0-122-generic|
|CPUs|Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz (12 x 1385)|
|Memory (System)|23.43GB (9.91GB free)|
|VM|0%|

|Item|Value|
|---|---|
|Remote|SSH: zjut.222.jinzcdev|
|OS|Linux x64 5.4.0-122-generic|
|CPUs|Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz (12 x 1478)|
|Memory (System)|23.43GB (9.91GB free)|
|VM|0%|
</details><details><summary>Extensions (10)</summary>

Extension|Author (truncated)|Version
---|---|---
pythonsnippets|frh|1.0.2
vscode-language-pack-zh-hans|MS-|1.70.8030922
jupyter-keymap|ms-|1.0.0
remote-containers|ms-|0.241.3
remote-ssh|ms-|0.84.0
remote-ssh-edit|ms-|0.80.0
material-icon-theme|PKi|4.19.0
svg-preview|Sim|2.8.3
jinja|who|0.0.8
material-theme|zhu|3.15.2

(1 theme extensions excluded)

</details><details>
<summary>A/B Experiments</summary>

```
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstes627:30244334
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vsdfh931:30280409
vshan820:30294714
vstes263:30335439
vscoreces:30445986
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30542924
vsaa593:30376534
vsc1dst:30438360
pythonvs932:30410667
wslgetstarted:30449410
vscscmwlcmt:30465135
cppdebug:30492333
vscaat:30438848
pylanb8912cf:30529770
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253

```

</details>

<!-- generated by issue reporter -->


Issue discussion:
EDIT: I found the log...

~~It looks like~~ I encountered the same problem. When upgrading to 1.70 the zsh shell only opens for the first remote user...


You can find the error log in `OUTPUT` of `Log (Remote Server)`, as shown below.
<img width="1099" alt="" src="https://user-images.githubusercontent.com/33695160/183677927-533a0a9e-6136-4192-96cc-9ee08b4ded23.png">
After I rolled the software back to the previous version, the issue was solved.


Thx, I found the log also now.

Rolling back to 1.69.2 and disabling auto update of VSCode solves the problem currently...

I hope the VSCode team will take care of this issue, for the next release
I tried also to find the line which is copying the file in the script, but was not really able to find it... I believe the command is hidden somewhere in the `__vsc_precmd` method

https://github.com/microsoft/vscode/blob/5a180f6a9e9d99a5c576e7c5a74c361f2559c398/src/vs/workbench/contrib/terminal/browser/media/shellIntegration-rc.zsh#L1-L132

Thanks for the report, you can workaround this by disabling shell integration automatic injection with `"terminal.integrated.shellIntegration.enabled": false` and then [installing it manually](https://code.visualstudio.com/docs/terminal/shell-integration#_manual-installation) in your `.zshrc`:

```sh
[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"
```
@Tyriar thanks, your workaround works!
@Tyriar yes thanks, I was having to go back to the previous release until @jinzcdev sent me here!
This is fixed in that it will no longer block the terminal from being created, as @roblourens called out in https://github.com/microsoft/vscode/pull/157900 though we need to make sure that multiple users are able to write the same file. We could perhaps solve this by moving the zsh shell integration files into their own folder in the bundle and just use that?
@Tyriar is this workaround still valid or should we be waiting for an update in vs code?
it's fixed in insider's @johncadengo, it's reopened bc of some complications that the fix has caused

Solution patch:
diff --git a/src/vs/platform/terminal/node/terminalEnvironment.ts b/src/vs/platform/terminal/node/terminalEnvironment.ts
--- a/src/vs/platform/terminal/node/terminalEnvironment.ts
+++ b/src/vs/platform/terminal/node/terminalEnvironment.ts
@@ -184,7 +184,7 @@ export function getShellIntegrationInjection(
 			newArgs = [...newArgs]; // Shallow clone the array to avoid setting the default array
 			newArgs[newArgs.length - 1] = format(newArgs[newArgs.length - 1], appRoot);
 			// Move .zshrc into $ZDOTDIR as the way to activate the script
-			const zdotdir = path.join(os.tmpdir(), 'vscode-zsh');
+			const zdotdir = path.join(os.tmpdir(), `${os.userInfo().username}-vscode-zsh`);
 			envMixin['ZDOTDIR'] = zdotdir;
 			const filesToCopy: IShellIntegrationConfigInjection['filesToCopy'] = [];
 			filesToCopy.push({


Test patch:
diff --git a/src/vs/platform/terminal/test/node/terminalEnvironment.test.ts b/src/vs/platform/terminal/test/node/terminalEnvironment.test.ts
--- a/src/vs/platform/terminal/test/node/terminalEnvironment.test.ts
+++ b/src/vs/platform/terminal/test/node/terminalEnvironment.test.ts
@@ -4,6 +4,7 @@
  *--------------------------------------------------------------------------------------------*/
 
 import { deepStrictEqual, ok, strictEqual } from 'assert';
+import { userInfo } from 'os';
 import { NullLogService } from 'vs/platform/log/common/log';
 import { ITerminalProcessOptions } from 'vs/platform/terminal/common/terminal';
 import { getShellIntegrationInjection, IShellIntegrationConfigInjection } from 'vs/platform/terminal/node/terminalEnvironment';
@@ -94,8 +95,14 @@ suite('platform - terminalEnvironment', () => {
 		if (process.platform !== 'win32') {
 			suite('zsh', () => {
 				suite('should override args', () => {
-					const expectedDir = /.+\/vscode-zsh/;
-					const expectedDests = [/.+\/vscode-zsh\/.zshrc/, /.+\/vscode-zsh\/.zprofile/, /.+\/vscode-zsh\/.zshenv/, /.+\/vscode-zsh\/.zlogin/];
+					const username = userInfo().username;
+					const expectedDir = new RegExp(`.+\/${username}-vscode-zsh`);
+					const expectedDests = [
+						new RegExp(`.+\/${username}-vscode-zsh\/\.zshrc`),
+						new RegExp(`.+\/${username}-vscode-zsh\/\.zprofile`),
+						new RegExp(`.+\/${username}-vscode-zsh\/\.zshenv`),
+						new RegExp(`.+\/${username}-vscode-zsh\/\.zlogin`)
+					];
 					const expectedSources = [
 						/.+\/out\/vs\/workbench\/contrib\/terminal\/browser\/media\/shellIntegration-rc.zsh/,
 						/.+\/out\/vs\/workbench\/contrib\/terminal\/browser\/media\/shellIntegration-profile.zsh/,