SFTP disconnects right after login
A customer's SFTP session closes at login, and OpenSSH logs fatal: bad ownership or modes for chroot directory "/home/USER" [postauth]. The customer's top folder must belong to root, and one command restores that ownership.
Symptoms
The SFTP client disconnects right after login with an error such as Connection reset by peer.
Check the sshd log with journalctl -u sshd on AlmaLinux or journalctl -u ssh on Ubuntu. It shows the following error.
fatal: bad ownership or modes for chroot directory "/home/USER" [postauth]Cause
SFTP confines each customer to /home/USER. The sshd service requires root to own that folder and every parent folder. Only root may have write permission on those folders.
Using chown to give the customer ownership of /home/USER breaks that requirement. This can happen when you run chown -R on the home folder. The customer's own files are in /home/USER/files.
Resolution
Preview the changes UrbeStack would make.
urbestack-home-repair --name USER --dry-runThe preview lists a change for
/home/USERfromUSER:roottoroot:root. Apply the repair.urbestack-home-repair --name USERThe folder
/home/USERnow has ownershiproot:rootand mode0755. Log in over SFTP again.