How to set seprate current directory for sftp in macos?

TechChain asked:

On my macos i am able to login to sftp as sftp localhost. When i run !pwd it shows me default directory is /Users/username but i want to change it /Users/username/Sites/wordpress.

I edited /etc/ssh/sshd_config file & added below lines at bottom of file

Match User username
       X11Forwarding no
       AllowTcpForwarding yes
       PermitTTY yes
       PasswordAuthentication yes
       ChrootDirectory /Users/username/Sites/wordpress

But when i again try to login with sftp localhost after password prompt it gives me error as below

client_loop: send disconnect: Broken pipe
Connection closed 

Please tell me how can fix this error ?

My answer:

You should configure sshd to use internal-sftp for SFTP, not the old external sftp-server binary.

Subsystem sftp internal-sftp

The internal-sftp can use a chroot directory without requiring any supporting files to be placed in that directory.

You may also read about all the other differences between internal-sftp and the old sftp-server.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.