CH-J Toolsserver management over SSH
Menu
All guides and articles →

SSH works but SFTP doesn't: causes and solutions

Find the difference between a successful SSH login, starting the SFTP subsystem, and file permissions. Diagnose configuration, chroot, disks, and transfers.

Successful terminal does not verify the entire file transfer

SSH is a secure transport that can provide a terminal, command execution, and SFTP subsystem. An account may authenticate successfully, but the request to run SFTP may be rejected by the server. And even a working SFTP may only have access to a specific directory. Therefore, it is necessary to distinguish between logging in, running the subsystem, reading directories, and writing a specific file.

SFTP is not FTP over TLS. It typically uses the same SSH connection and TCP port as the terminal, without the passive data ports known from FTP. If SSH works and only SFTP fails, opening a range of ports for FTP will usually not fix anything and may unnecessarily increase network access. First, verify that you are using the SFTP protocol, the correct host, port, account, and key in your client.

  • Failure before user authentication: look for the same network or login cause as for SSH.
  • Subsystem request failed: check the server subsystem and account restrictions.
  • The directory opens, but the file cannot be saved: check the permissions, disk status, and storage method.
  • The transfer starts and then stops: compare space, quotas, network, and server logs.

Compare clients with the same goal and identity

As a check, use the OpenSSH client with verbose output. If the graphical client fails but the command line client works, you have a basis for checking its profile or compatibility. The comparison is only meaningful for the same account and port. One profile may have a bastion and another a direct connection; then you are not testing the same path.

ssh -vvv -p 22 -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes spravce@server.example
sftp -vvv -P 22 -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes spravce@server.example

Note the capital -P for sftp versus the lowercase -pu for ssh. Look in the output to see if authentication occurred and when the client requested the sftp subsystem. Before sharing the logs, remove account names, internal addresses, and other identifiers that are not intended to be public. Do not include the private key or passphrase in the log.

# Po úspěšném připojení v interaktivním sftp:
pwd
ls -la
# Ukončení:
bye

Start by reading. Uploading or overwriting the actual configuration is not a good first test. If you need to verify the write, choose an approved empty test file in a directory that you are actually allowed to use for this, and delete it purposefully after verification. Do not confuse the test in the home directory with the test of permissions to /etc or the webroot.

Verify Subsystem configuration and daemon entries

OpenSSH needs to know how to handle the sftp subsystem. It can use the separate sftp-server binary or the internal implementation internal-sftp. The paths to the external binary vary between distributions; do not download them from a foreign system. A missing file after a partial update or an invalid path may explain why the shell works but the transfers do not even open.

sudo /usr/sbin/sshd -t
sudo /usr/sbin/sshd -T | grep "^subsystem "
sudo journalctl -u ssh.service --since "-15 min" --no-pager

# Jedna možná deklarace, pokud odpovídá zamýšlené politice:
Subsystem sftp internal-sftp

On a distribution with sshd.service, change the unit name. Do not add a second declaration of the same subsystem without checking the existing settings. The modification is a server policy change and should have a backup, sshd -t check, managed reload, and test for a new connection. It does not require a global elevation of privileges to all users.

When you need more detailed logging, enable it selectively and for a limited time depending on the SFTP implementation you are using. Some operations or file names may leak sensitive information into the log. Additionally, the availability of the logging socket may vary with chroot. After resolving the issue, revert the temporary logging level to avoid unnecessary ongoing diagnostic overhead.

Match, ForceCommand, and specific key restrictions

An account can have individual rules based on user, group, or source address. ForceCommand can run its own wrapper that allows a terminal command but does not pass the request to the subsystem. A similar restriction can be placed directly on the public key in authorized_keys. Therefore, compare the actual key used and the connection context, not just the general settings for root.

sudo /usr/sbin/sshd -T -C user=spravce,addr=203.0.113.10,host=klient.example \
  | grep -E "^(forcecommand|chrootdirectory|permittty|subsystem) "

Replace user and addr with the actual context. The listing does not automatically explain every restriction in authorized_keys or the behavior of the wrapper itself. Check them specifically with your account administrator. If the account is only intended for the backup command, denying SFTP may be the correct behavior. In that case, the solution is to use a separate account or allow a transfer path, not to remove all restrictions.

If the log reports unexpected data or a message that is too long, check scripts running in a non-interactive session and your own commands. Printing a banner or echoing to standard output can break the log. Do not remove login scripts in general; fix specific unconditional output. Diagnostic text belongs in the correct channel, not in SFTP binary messages.

Chroot: correct directory boundary and writable subdirectory

ChrootDirectory changes the account's view of the file system. For example, the / address inside SFTP might correspond to /srv/sftp/zakaznik on the host. If you look for a file by its host absolute path, it doesn't exist inside the sandbox. Start pwd and ls and describe both mappings before any ownership changes.

OpenSSH checks the ownership and writability of the chroot path. A typical secure design is a root-owned boundary with no regular account writability, and a separate user-owned upload directory inside. Adding writability to the root of the chroot itself can cause the session to be rejected. Therefore, do not fix the problem with chmod -R 777.

# Čtecí kontrola jednotlivých komponent cesty na Linuxu:
namei -l /srv/sftp/zakaznik/upload
ls -ld /srv /srv/sftp /srv/sftp/zakaznik /srv/sftp/zakaznik/upload

An external sftp-server inside a chroot needs a proper environment; internal-sftp removes many of these dependencies. However, the choice of implementation must respect existing logging and rules. Do not confuse a quick subsystem switch with a complete isolation check. After the fix, verify that the user sees only the intended data and writes only to the reserved subdirectory.

Permission denied when saving does not mean broken SFTP

Read and write are different permissions. In addition, saving an existing file can be done via a temporary file and then renaming it. Such a procedure requires appropriate permissions to the directory, even if the target file itself is writable. Check the owner, group, traversal of all directories, ACL and any sticky bit. Change permissions for a specific file or directory.

id
namei -l /cesta/k/souboru
ls -ld /cesta/k /cesta/k/souboru
getfacl /cesta/k /cesta/k/souboru

Access via sudo in the terminal does not automatically transfer to the already running SFTP subsystem. Therefore, an administrator can read a file via sudo, but regular SFTP will not save it. Do not enable general root login for this reason. For administrative configurations, use an approved procedure with a temporary file, change control, and targeted installation with the correct owner and permissions.

In CH-J Tools, it makes sense to separate the transfer via the file manager from the administrative operation in the terminal. If the editor warns of a concurrent change, compare versions instead of forcing an overwrite. Server permissions and conflict detection solve different problems: a successful write does not mean that you have not deleted the newer work of another administrator.

Free blocks, inodes, quotas, and read-only filesystem

If an error occurs during upload, check the capacity of the target filesystem, the number of free inodes, and the account quota. Free space on / does not say anything about another mounted volume you are writing to. Also, temporary editor files or moving between filesystems may have a different claim than simply overwriting a small file.

df -h /cesta/k/cili
df -i /cesta/k/cili
findmnt -T /cesta/k/cili
quota -s

The quota tool does not need to be installed and its output is only meaningful when quotas are in use. If findmnt shows ro mode, find out the reason for the read-only mount. This may be a protective reaction after storage errors. Automatic remount to rw without checking kernel entries could worsen the damage. For network storage or containers, also consider the rules of its administrator.

Post-repair verification and client error resolution

After the repair, open a new SFTP connection, list the intended directory, and perform a small approved transfer test. If you are dealing with integrity, compare the checksum of the local and remote files. For interrupted transfers, do not recklessly include a continuation into a file with unknown content: the same length of an already existing part is not proof of its consistency.

  • The login uses the same identity you wanted to fix.
  • The subsystem starts without error and the server log does not show a new problem.
  • The account reads and writes to the intended location, not a random test directory.
  • Chroot, permissions, and security restrictions are preserved.
  • If only one client has problems, you have a comparable successful test by another client.

Before submitting an issue to support, collect the client and server versions, the exact message, time, and stage of the error. Do not attach private keys or an entire configuration archive with secret data. A properly described difference between a terminal, running a subsystem, and the permission for a specific operation is often more helpful than saying "SFTP just doesn't work."

Frequently asked questions

Do I need to enable additional ports for SFTP?

Regular SFTP uses SSH transport, usually the same TCP port. It is not passive FTP and does not require its data port range.

Why does sudo work in the terminal but writing via SFTP doesn't?

SFTP runs under the logged-in account. Privileges obtained with a separate sudo command are not automatically transferred to this subsystem.

Will chmod 777 help on chroot?

No. The writable boundary of the chroot can be rejected by OpenSSH and broad permissions would worsen isolation. A dedicated internal directory should be writable.

Can the client block overwriting even with the correct permissions?

Yes. The editor may detect a concurrent change or need a temporary file and rename. Examine the specific operation and compare the contents.

Detailed documentation

OpenSSH: SFTP client →

OpenSSH: SFTP server →

OpenSSH: Subsystem, ChrootDirectory and ForceCommand →

OpenSSH: restrictions in authorized_keys →

Biometric unlock and security →

All tutorials by category →