PSFTP Connection Automatically Closing: Keypress Issue

Abstract: Resolve PSFTP connections closing on keypress by changing the user's shell in /etc/passwd to /usr/sbin/nologin to prevent interactive shell assignment.

Created: 2026-08-09 by

PSFTP connections closing upon keypress usually stem from the SSH client interpreting standard input as an interactive shell command rather than SFTP protocol data. This occurs when the server assigns a login shell to the user instead of the SFTP subsystem, causing the terminal to process keystrokes immediately after authentication. Disabling shell access or forcing the SFTP subsystem resolves this behavior by ensuring the connection remains dedicated to file transfer operations.

Understanding the Root Cause

The Secure File Transfer Protocol (SFTP) operates over an SSH connection. When you initiate a session with psftp, the SSH daemon on the remote server must decide how to handle the authenticated user. By default, many Linux distributions configure the user account to have a valid login shell, such as /bin/bash or /bin/sh. When PSFTP connects, it requests the sftp subsystem. However, if the server configuration or user profile forces an interactive shell session, the terminal becomes active. In this state, any keystroke you press is sent directly to the shell for interpretation. The SFTP client, expecting binary protocol responses, receives unexpected character data and may disconnect or behave erratically because the stream is no longer purely SFTP traffic. This is distinct from network timeouts or permission errors; it is a fundamental mismatch between the client's expectation of a file-transfer-only channel and the server's provision of an interactive terminal.

Verifying the Shell Assignment

To confirm if this is the issue, check the user's entry in the /etc/passwd file on the server. If the last field is set to a valid shell path rather than /sbin/nologin or /usr/sbin/nologin, the user is permitted to log in interactively. While some workflows require shell access for administrative tasks, using the same account for automated or script-based SFTP transfers via PSFTP can lead to these closure issues. For environments requiring multiple file sources, proper directory setup is crucial to maintain security boundaries. You can review best practices for managing these directories in our guide on Setting up SFTP Directory for Multiple File Sources on Linux Server.

Solutions for Interactive Closure

There are two primary approaches to resolve this: restricting the user's shell access or configuring PSFTP to ignore interactive prompts. The preferred method for security and stability is to restrict shell access, ensuring the account is used exclusively for file transfers.

Method 1: Restricting User Shell Access

If the user account does not require command-line access, modify the shell path in /etc/passwd to a non-interactive option. This prevents the SSH daemon from launching a shell upon authentication, forcing the connection to remain within the SFTP subsystem. 1. Open the /etc/passwd file with root privileges using a text editor like vi or nano. 2. Locate the line corresponding to the SFTP user. It typically looks like:
username:x:1001:1001::/home/username:/bin/bash
3. Change the final field (/bin/bash) to /usr/sbin/nologin or /sbin/nologin. 4. Save the file and exit. After making this change, the next time the user attempts to connect via SSH or PSFTP, the server will reject interactive shell requests. The SFTP subsystem will still function correctly because it is handled separately by the SSH daemon's internal routing. Note that this change affects all SSH connections for that user, so ensure they do not need shell access for other purposes. If you encounter permission issues after adjusting paths, refer to our troubleshooting guide on SFTP returning permission denied despite correct directory permissions: A tech support guide to verify chroot jail settings.

Method 2: Configuring SSH Daemon for SFTP Only

Alternatively, you can keep the user's shell but force the SSH daemon to use only the SFTP subsystem for specific users. This is achieved through the ForceCommand directive in /etc/ssh/sshd_config. 1. Edit /etc/ssh/sshd_config as root. 2. Add a block for the specific user or group:
Match User sftpuser
    ForceCommand internal-sftp
3. Restart the SSH service to apply changes:
sudo systemctl restart sshd
This configuration ensures that even if the user has a valid shell defined, the SSH daemon overrides it and invokes the internal SFTP server. This method is safer than modifying /etc/passwd directly because it allows for granular control without altering user system accounts.

Alternative Clients and Workarounds

If modifying server configurations is not feasible due to policy restrictions, consider using alternative clients that handle interactive shells more gracefully. Some GUI-based SFTP clients allow you to specify whether to request an interactive shell or stick strictly to file transfer protocols. Additionally, using SSH keys with strict host key checking can help isolate connection issues from authentication problems. For setups requiring enhanced security layers, such as Multi-Factor Authentication, ensure your client supports the required MFA flows to prevent interruptions during the handshake phase. Learn more about securing these transfers with SFTP Requires MFA: How to Upload/Download Files Securely.

Troubleshooting Persistent Issues

If the connection still closes unexpectedly after applying the above fixes, check the SSH server logs (/var/log/auth.log or /var/log/secure). Look for messages indicating "Subsystem request failed" or "Received disconnect." These errors often point to configuration mismatches in sshd_config, such as incorrect Subsystem sftp paths. Ensure that the path specified matches the actual location of the SFTP server binary on your distribution. Common paths include /usr/lib/openssh/sftp-server or /usr/libexec/openssh/sftp-server. Misconfigurations here can cause immediate disconnection upon subsystem request. For broader connection error diagnostics, consult our article on Troubleshooting SFTP Connection: Subsystem Request Failed.

Frequently Asked Questions

Why does PSFTP work with some servers but not others?

The difference lies in how each server configures the user's default shell. Servers that assign /bin/bash by default will trigger the keypress closure issue, while those configured with /sbin/nologin or forced SFTP commands will not. Always verify the server's PAM and SSH configurations to understand the expected behavior.

Can I use PSFTP if the user needs shell access?

It is generally discouraged to mix interactive shell access with automated SFTP clients like PSFTP. If shell access is required, consider using a different tool like scp or an SFTP client that explicitly handles interactive sessions, such as WinSCP in interactive mode, which manages the terminal state better than command-line PSFTP.

What is the difference between SFTP and FTPS regarding shell access?

SFTP runs over SSH and shares the same authentication mechanism as the shell, meaning shell access controls SFTP availability. FTPS runs over explicit TLS and is typically handled by a separate daemon (like vsftpd) that does not rely on the system's login shell, allowing file transfer without granting shell access.

How do I test if my SSH server is sending a shell instead of SFTP?

Connect to the server using ssh -v username@host and watch the verbose output. If you see "Entering interactive session" followed by shell prompts, the server is providing a shell. If it says "Authenticated" and then immediately offers SFTP commands or stays silent waiting for protocol data, the configuration is correct.

Does disabling shell access affect password changes?

Yes, if the shell is set to /sbin/nologin, users cannot change their passwords via the passwd command unless you configure sudo rules to allow specific commands. Consider using /bin/false if you want to allow specific authorized commands while blocking general shell access, though /usr/sbin/nologin is the standard for SFTP-only accounts.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More