Doesn't delete a folder with subfolders or files
Is it possible somehow to delete the entire folder at once if other folders and files are nested in it? Now you need to first delete everything in the subfolders, and only then you can delete the folder itself. How to get around this?
Can you post the SSH FS log? It is available under Output > SSH FS. While it should censor passwords/passphrases, I recommend checking it for (other) sensitive data first.
Did this issue start since a certain VS Code version? Or have you never used this extension before?
I decided to try it for the first time, and tried to delete the directory with subdirectories and files. But I have an error. Therefore, you have to initially delete everything that is in the directory and then the directory itself.
Which OS and SSH version is your remote server running? The extension should already be able to delete directories recursive, assuming the SSH server supports it and VS Code actually tells the extension to do it: https://github.com/SchoofsKelvin/vscode-sshfs/blob/48ef2298a8985c5748680d66477ea31c841f8592/src/sshFileSystem.ts#L153-L167
SSH 2, Ubuntu 21.04
I assume OpenSSH in that case? Version v8.x or so? My test server runs Ubuntu 20.04 with OpenSSH 8.2, I'll try to replicate this issue.
Any update on this? Still getting a pop-up saying "Failure" when trying to delete a non-empty folder. Using Ubuntu 20.04.3 LTS with OpenSSH_8.2p1 Ubuntu-4ubuntu0.3, OpenSSL 1.1.1f on remote.
Output is
[DEBUG] Deleting ssh://myusername/var/www/mywebsite/wwwroot
[ERROR] Error handling uri: ssh://myusername/var/www/mywebsite/wwwroot
Error: Failure
JSON: {"code":4,"lang":""}
Error: Failure
at k._transform (c:\Users\MyUser\.vscode\extensions\kelvin.vscode-sshfs-1.24.1\dist\14f8.extension.js:1:82647)
at k.Transform._read (internal/streams/transform.js:205:10)
at k._read (c:\Users\MyUser\.vscode\extensions\kelvin.vscode-sshfs-1.24.1\dist\14f8.extension.js:1:78652)
at k.Transform._write (internal/streams/transform.js:193:12)
Logged at:
at c:\Users\MyUser\.vscode\extensions\kelvin.vscode-sshfs-1.24.1\dist\f1d0.extension.js:1:3486
I did test this, but the only way I was able to reproduce the error by deleting a non-empty directory was by having it contain a file I don't own. E.g. this is how my test folder I tried to remove (as test-user) looks like:
drwxr-xr-x 2 root root 4.0K Dec 21 17:58 .
drwxr-xr-x 7 test-user test-user 4.0K Dec 21 17:58 ..
-rw-r--r-- 1 test-user test-user 0 Dec 21 17:58 a
-rw-r--r-- 1 root root 0 Dec 21 17:58 b
-rw-r--r-- 1 test-user test-user 0 Dec 21 17:58 c
Is this the cas for any of you? The "you need to first delete everything in the subfolders" makes it seem as if you're able to delete the contents using VS Code's Explorer, which would indicate it isn't a permission issue.
Does sshd provide any useful logs (perhaps after setting LogLevel to DEBUG3) regarding this?
I added a folder under /home with a file in it via sshfs VS Explorer. Both were created with root owners. I tried deleting the folder via sshfs VS Explorer and got the same error. Then I changed ownership of both the folder and the file to my current ssh user, tried deleting again, and got the same error. I also added DEBUG3 but the log is the same. Probably I added it to the wrong place. I tried both the following things in settings.json :
"sshfs.configs": [
{
"name": "myname",
"host": "myip",
"username": "myusername",
"password": "mypassword",
"sftpSudo": true,
"LogLevel": "DEBUG3"
}
]
"sshfs.flags": ["DEBUG3"]
Also I can delete the file inside /home via sshfs VS Explorer and then the empty folder too. Even when the owner is root so I don't think it's a permission issue.
I meant adding LogLevel DEBUG3 to your sshd_config on the server (and restarting the sshd service). It should increase the amount of logs in whatever logfile sshd writes to, which is e.g. /var/log/auth.log on Ubuntu.
I see you're using sftpSudo which should mean your SFTP user is actually root, not the user you login with. I'll test whether I can reproduce it that way.
This is my log at the time of the failed delete attempt (attempt was between 14:21:50 and 14:22:00 but there could be a slight clock mismatch between local and remote I guess):
Dec 22 14:21:49 myvirtualservers sshd[1642]: debug1: PAM: password authentication failed for root: Authentication failure
Dec 22 14:21:49 myvirtualservers sshd[1642]: debug3: mm_answer_authpassword: sending result 0
Dec 22 14:21:49 myvirtualservers sshd[1642]: debug3: mm_request_send entering: type 13
Dec 22 14:21:49 myvirtualservers sshd[1642]: Failed password for root from MyIp port 43710 ssh2
Dec 22 14:21:49 myvirtualservers sshd[1642]: debug3: mm_auth_password: user not authenticated [preauth]
Dec 22 14:21:49 myvirtualservers sshd[1642]: debug3: user_specific_delay: user specific delay 0.000ms [preauth]
Dec 22 14:21:49 myvirtualservers sshd[1642]: debug3: ensure_minimum_time_since: elapsed 1941.617ms, delaying 1181.590ms (requested 6.100ms) [preauth]
Dec 22 14:21:50 myvirtualservers sshd[1642]: debug3: userauth_finish: failure partial=0 next methods="publickey,password" [preauth]
Dec 22 14:21:50 myvirtualservers sshd[1642]: debug3: send packet: type 51 [preauth]
Dec 22 14:21:50 myvirtualservers sshd[1642]: debug3: receive packet: type 1 [preauth]
Dec 22 14:21:50 myvirtualservers sshd[1642]: Received disconnect from MyIp port 43710:11: Bye Bye [preauth]
Dec 22 14:21:50 myvirtualservers sshd[1642]: Disconnected from authenticating user root MyIp port 43710 [preauth]
Dec 22 14:21:50 myvirtualservers sshd[1642]: debug1: do_cleanup [preauth]
Dec 22 14:21:50 myvirtualservers sshd[1642]: debug3: PAM: sshpam_thread_cleanup entering [preauth]
Dec 22 14:21:50 myvirtualservers sshd[1642]: debug1: monitor_read_log: child log fd closed
Dec 22 14:21:50 myvirtualservers sshd[1642]: debug3: mm_request_receive entering
Dec 22 14:21:50 myvirtualservers sshd[1642]: debug1: do_cleanup
Dec 22 14:21:50 myvirtualservers sshd[1642]: debug1: PAM: cleanup
Dec 22 14:21:50 myvirtualservers sshd[1642]: debug3: PAM: sshpam_thread_cleanup entering
Dec 22 14:21:50 myvirtualservers sshd[1642]: debug1: Killing privsep child 1643
Dec 22 14:21:50 myvirtualservers sshd[1642]: debug1: audit_event: unhandled event 12
Dec 22 14:21:50 myvirtualservers sshd[697]: debug1: main_sigchld_handler: Child exited
Dec 22 14:21:51 myvirtualservers sshd[1447]: debug2: channel 0: rcvd adjust 1063836
Dec 22 14:21:53 myvirtualservers sshd[1447]: debug2: channel 0: rcvd adjust 1058012
Dec 22 14:21:54 myvirtualservers sshd[1447]: debug2: channel 0: rcvd adjust 1063883
Looking at your code I saw sftp.rmdirthere. Isn't rmdir only for empty folders and rm -r is for non-empty folders?
This sftpSudo thingy seems to be active out of the box since I didn't change anything on Ubuntu and sshfs config says SFTP Sudo Optional <Default>. Anyway it seems to be a good thing because with MobaXterm file editor I couldn't save a single file after editing because of permission errors. With sshfs I could edit and save all files without problem so far ♥
Ah, in the settings UI, it might not be very clear, but there's an empty option (e.g. leaving the textfield empty) followed by the <Default> option. The default option is to indicate it'll just use sudo without the -u user flag, therefore using the default value of your OS (e.g. root). Maybe I should make it display that option as <None> or something similar instead.
I'll still test for it. As for your logs, they're a bit confusing. I see a failed password login attempt, but otherwise than that no mention of SFTP or even another data channel (besides the 0 channel that should be a shell). Might indeed be the wrong timestamps, or even issues with time zones. I usually just tail -f /var/log/auth.log, quickly do what I want to do, then Ctrl+C.
The sftp.rmdir is the recursive version similar to rm -r, while the sftp.unlink resembles the regular non-recursive rm.
I did the tail technique but the logs don't look more useful than before:
Dec 22 16:59:40 myvirtualservers sshd[7169]: debug1: audit_event: unhandled event 12
Dec 22 16:59:40 myvirtualservers sshd[697]: debug1: main_sigchld_handler: Child exited
Dec 22 16:59:56 myvirtualservers sshd[1447]: debug2: channel 0: rcvd adjust 1054907
Dec 22 16:59:57 myvirtualservers sshd[1447]: debug2: channel 0: rcvd adjust 1057759
Dec 22 16:59:58 myvirtualservers sshd[1447]: debug2: channel 0: rcvd adjust 1048784
Dec 22 17:00:00 myvirtualservers sshd[1447]: message repeated 3 times: [ debug2: channel 0: rcvd adjust 1048784]
Dec 22 17:00:00 myvirtualservers sshd[1447]: debug3: receive packet: type 80
Dec 22 17:00:00 myvirtualservers sshd[1447]: debug1: server_input_global_request: rtype [email protected] want_reply 1
Dec 22 17:00:00 myvirtualservers sshd[1447]: debug3: send packet: type 82
Dec 22 17:00:00 myvirtualservers sshd[1447]: debug2: channel 0: rcvd adjust 1048784
Dec 22 17:00:07 myvirtualservers sshd[1447]: message repeated 9 times: [ debug2: channel 0: rcvd adjust 1048784]
Dec 22 17:00:07 myvirtualservers sshd[1447]: debug2: channel 0: rcvd adjust 1052778
Dec 22 17:00:07 myvirtualservers sshd[1447]: debug2: channel 0: window 1998737 sent adjust 98415
Dec 22 17:00:07 myvirtualservers sshd[1447]: debug2: channel 0: rcvd adjust 1057649
Dec 22 17:00:08 myvirtualservers sshd[1447]: debug2: channel 0: rcvd adjust 1050670
Dec 22 17:00:08 myvirtualservers sshd[1447]: debug2: channel 0: rcvd adjust 1051561
Dec 22 17:00:09 myvirtualservers sshd[1447]: debug2: channel 0: rcvd adjust 1052125
Dec 22 17:00:09 myvirtualservers sshd[1447]: debug2: channel 0: rcvd adjust 1055333
Indeed nothing useful it seems. I'll do some tests on my server later, in the meantime you can try setting the SFTP Sudo field to an empty value, see if that's interfering. If you're authenticating as root, there's no reason to use that option anyway.
Changing the SFTP Sudo to an empty value didn't do anything I think, so in ssh.configs I changed "sftpSudo": true to "sftpSudo": false. This changed things. The pop-up doesn't say "Failure" now but "ssh://myuser/home/myfolder". (myfolder is the non-empty folder with root owner I tried to delete).
The sshfs log is:
[DEBUG] Deleting ssh://myuser/home/myfolder
[ERROR] Error handling uri: ssh://myuser/home/myfolder
Error: Permission denied
JSON: {"code":3,"lang":""}
Error: Permission denied
at k._transform (c:\Users\MyUser\.vscode\extensions\kelvin.vscode-sshfs-1.24.1\dist\14f8.extension.js:1:82647)
at k.Transform._read (internal/streams/transform.js:205:10)
at k._read (c:\Users\MyUser\.vscode\extensions\kelvin.vscode-sshfs-1.24.1\dist\14f8.extension.js:1:78652)
at k.Transform._write (internal/streams/transform.js:193:12)
Logged at:
at c:\Users\MyUser\.vscode\extensions\kelvin.vscode-sshfs-1.24.1\dist\f1d0.extension.js:1:3486
[DEBUG] Error converted to: NoPermissions (FileSystemError): ssh://myuser/home/myfolder
I think that is the expected behavior because now it's a permission problem.
The auth.log tail log didn't log a single thing during the failed delete attempt.
Next thing I tried is creating under /home/myuser a folder with a file in it while still having "sftpSudo": false. When trying to delete the folder I get the other non-permission-related error (the "Failure" pop-up and so on.) Then I switched back to "sftpSudo": true` and tried to delete the folder I got the same error.
To summarize: With "sftpSudo": false I get a permission error when trying to delete stuff owned by root which is as expected. All the other variations give an error that is not permission related I think but of another mysterious kind.