SchoofsKelvin / vscode-sshfs

Extension for Visual Studio Code: File system provider using SSH
GNU General Public License v3.0
543 stars 36 forks source link

Couldn't detect the home directory for 'configuration' #273

Closed tlaerm closed 3 years ago

tlaerm commented 3 years ago

I have a weird issue with one server, that has a nonstandard ssh port. When opening a terminal or trying to add the folder to workspace I get the same error: Couldn't detect the home directory for 'configuration' Debug output is as follows:

[INFO]    Command received to open a terminal for FileSystemConfig(configuration)
[INFO]    [createConnection(configuration,config)] Creating a new connection for 'configuration'
[INFO]    Calculating actual config
[DEBUG]     Final configuration:
{
    "name": "configueation",
    "host": "host.name",
    "port": NONSTANDARD-PORT,
    "username": "root",
    "agent": "/tmp/ssh-XXXXXXtzOm0y/agent.1292",
    "root": "/root/",
    "_location": 1,
    "_locations": [
        1
    ],
    "_calculated": {
        "name": "configuration",
        "host": "host.name",
        "port": NONSTANDARD-PORT,
        "username": "root",
        "agent": "$SSH_AUTH_SOCK",
        "root": "/root/",
        "_location": 1,
        "_locations": [
            1
        ]
    }
}
[INFO]    [createSocket(configuration)] Creating socket
[DEBUG]   [createSocket(configuration)] Connecting to host.name:NONSTANDARD-PORT

Running on Linux Vscodium 1.57.1 vscode-sshfs v1.21.0 Host is Ubuntu 20.04 Connecting in the terminal with ssh root@host.name -p NONSTANDARD-PORT works fine. I'd be really grateful for any pointers. vscode-sshfs works flawlessly for other hosts.

Thomas

SchoofsKelvin commented 3 years ago

What is the actual home directory for the root user? E.g. what would echo ~ output, and does that path lead to a directory your user can actually access?

SchoofsKelvin commented 3 years ago

I've pushed a small commit (bda36c9) which you can download here (or from later builds).

Besides displaying a better warning in the output log, it also allows you to add a -CHECK_HOME flag (see #270 on how) and it should ignore this error and default the home directory to / instead. As long as you don't use ~ anywhere (except terminals, since those run on the server), it shouldn't affect anything anyway.

tlaerm commented 3 years ago

echo ~ indeed gives /root on the server. Your patch works when I run with "-CHECK_HOME" flag.

Thank you for getting into this so quickly.

SchoofsKelvin commented 3 years ago

I'm still interested in what caused this. Detecting the home directory is done by running an echo Home: ~ and looking for "Home: ..." in the output, as can be seen here:

https://github.com/SchoofsKelvin/vscode-sshfs/blob/bda36c998c4b6a65de02a246324712cf8bea4590/src/connection.ts#L24-L33

Are you using a special shell for the root user, different from sh/bash? (Pretty sure OpenSSH copies your user shell). What OS are you using? And just regular OpenSSH I assume, apart from running on a different port?

tlaerm commented 3 years ago

Sorry for the delay. So, the box uses fish as default shell. This however gives the same result to the echo Home: ~ command. I have tested again and now it works even without the flag. There is an explanation however: After your patch I still could not connect and got another error: Unexpected packet before version I checked issue #185 and silenced a script that was adding some ssh keys to the agent on login. After silencing the login completely, it worked. So this leads me to believe that both problems are related to this. Maybe the tryGetHome call is somehow interrupted or confused because the shell is sending some output from the login script.

SchoofsKelvin commented 3 years ago

Hmm, I do use the regex /^Home: (.*?)\r?\n?$/, which would fail should anything appear before (or even after) the echo.

I'll see about merging tryGetHome into the background command shell from #267 where it runs echo ::sshfs:home:$(echo ~) instead and checks for the pattern in all stdout lines, making it immune to weird shell startup or weird P1 etc. Good to know login scripts can break this, thanks for discovering that.

If your login script still runs for SFTP sessions like in #185, then that's not something I can solve I think. It should run the shell non-interactively which might help configuring the script, although I'm not too sure about how the underlying ssh2 library handles SSH subsystem "shells" for e.g. SFTP.

tlaerm commented 3 years ago

Alright. That sounds like it should solve the problem. Ping me when you want it tested. I'll de-silence the login.

pelesh commented 2 years ago

I am running into similar issue with SSH FS extension v1.24.1. When I try to log in I get an error message "Couldn't detect the home directory for 'configuration'".

My json config is:

{
    "sshfs.configs": [
        {
            "name": "configuration",
            "host": "remotehostname.org",
            "username": "myusername",
            "root": "/my/homedir/path",
            "flags": ["CHECK_HOME"]
        }
    ]
}

I checked that /my/homedir/path is what I get when I echo ~ on the remote.

Could you suggest how to troubleshoot this? I haven't used this plugin before, so I might be missing something obvious.

luckman212 commented 10 months ago

@pelesh I think the flag needs a dash:


{
    "sshfs.configs": [
        {
            ...
            "flags": ["-CHECK_HOME"]
        }
    ]
}