Celeb Glow
updates | March 29, 2026

Allow SFTP file transfer over a severely limited SSH connection

For various reasons, I need to allow only one SSH connection to a server for a specificuser at a time, and when they log in, a command needs to be executed right away, limiting them in what they can do.

I thus created a script /usr/local/bin/limit-sshd (based on this question and answer) which is executed when an SSH connection is established (using ForceCommand in /etc/ssh/sshd_config) and which, very simplified, looks like this

#!/bin/bash
if [[ $USER == specificuser ]]
then /run/this/command
else ...
fi

The use case for which this was created now includes file transfer to the server which you could typically achieve using an SFTP client such as pscp.

I am on a Windows machine using PuTTY and have a configuration for the server that I need to access; the configuration includes the sharing of the SSH connection. I can log in to the machine. On my Windows command line I then tried

pscp -load configuration c:\path\to\file_to_copy specificuser@<server IP>:/path/to/destination

This works with a user that does not have the limitations described above, but fails with

FATAL ERROR: Received unexpected end-of-file from server

I'm assuming this is due to the fact that there is some command passed via the SSH connection that the server cannot handle because of how I set things up above.

(How) can I enable file transfers over this connection?

4 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy