I've setup the built-in OpenSSH in Windows 10 and connected remotely via WinSCP SFTP protocol. I seem to have access to all folders in my C:
drive, but I cannot access the external drives of my computer. Going to the "root" folder just lists the C:
drive. I tried creating a soft directory symlinks in a directory that I can access, but that doesn't seem to work. They appear as files in WinSCP and I cannot access them. How can I add them? Also, is there a way to restrict access to certain folders if I wanted to share access to only certain folders of my server?
3 Answers
While some Windows SFTP servers do implement a virtual root folder which lists available drives, Win32-OpenSSH does not. It redirects the root folder /
to /C:/
(or maybe to a system drive).
If you want to visit another drive, you have to manually change a working directory.
In WinSCP GUI, you can do that using "Open Directory" command and typing a path to the desired drive, like
/D:/
.In command-line SFTP clients, like OpenSSH
sftp
, PuTTYpsftp
or WinSCP scripting, you can usecd
command, like:cd /D:/
There's actually WinSCP FAQ for How do I change drive on the remote panel?
Regarding your attempt to solve this using a symlink: A symlink really shows as a file in WinSCP (as the server presents it as an unknown file type). But a directory junction shows as a directory (the server presents it as a regular directory, not a link). Though since WinSCP 5.14.2, you can make WinSCP try to enter "file" using Ctrl+PgDn.
-
I have tried to create such a junction using the mklink command in Windows, like this: mklink /D C:\D D:\. However, when I do so, I cannot copy any files to subfolders in /D, it says "access denied" in WinSCP, although when I map the D-rive directly as ChrootDirectory, this works. So by linking, I lose some file permissions, can I set them directly anyhow?– ErikJun 7, 2019 at 10:00
-
/D
does not create a junction. It creates a folder symbolic link. Junction is created by/J
. Though I actually cannot reproduce the problem with symlink (I have described in my answer) anymore. For me even symbolic link works. Maybe they have fixed it meanwhile. Anyway, try/J
. Jun 7, 2019 at 10:10 -
It looks like this doesn't work as well for me, it also says in the permissions rwx------. And another thing I noticed is that it tries to create the file as myfile.txt..filepart, which works, so I have that file with size 0, so maybe some renaming process fails? Looks really strange to me, all I can say that the behaviour is similar in WinSCP as in Filezilla, so I guess I need to set some permissions on serverside, but where is the right place to look?– ErikJun 7, 2019 at 11:21
-
Windows OpenSSH server follows permissions of your Windows account. There's nothing to be set specifically for the SFTP/SSH server. The permissions you see in WinSCP are not really relevant. There's no way the server can map complex Windows ACL to simple *nix-style permissions that you see in WinSCP. -- If you login with an SSH terminal client, can you create files on the junction/symlink? Jun 7, 2019 at 12:26
-
Martin, thanks for your reply, it works when I copy the files using putty and an open SSH-connection. Also see my other comment how to reproduce the steps using Filezilla (WinSCP will behave like FIlezilla there)– ErikJun 11, 2019 at 8:43
On server machine, change default command shell as "PowerShell".
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force
Refer this link This change should solve your problem.
-
How does changing the default shell enable adding/removing drives to the OpenSSH SFTP server. I don't get it.– zx485Jul 13, 2020 at 17:27
There seems to be a bug/glitch when using openssh with the default "cmd.exe" shell. At least on my system, when you change the drive letter from c: to d: the dir listing doesn't refresh, even if you do cls first. But with powershell, if you do cls in between, then it works.