Create an SFTP connection on local machine to make tests.
1sudo systemsetup -setremotelogin on
2
3# Test connection
4sftp localhost
5# or
6sftp <username>@localhost
7
8# Don't forget to stop the server when done
9sudo systemsetup -setremotelogin off<username> is your system username (/User/username/)If you need credentials for app to connect to this SFTP connection,
1host = 'localhost'
2port = 22
3username = '<username>'
4password = 'your-system-login-password'1# Create the SFTP root folder (read only)
2sudo mkdir -p /Users/sftp-root
3sudo chown root:wheel /Users/sftp-root
4sudo chmod 755 /Users/sftp-root # only root can write to it
5sudo mkdir -p /Users/sftp-root/upload
6sudo chown <username>:staff /Users/sftp-root/upload<username> can only access to /files. ⚠️ The location of sftp-root here (which is in /Users/) is important. Other places may lead to error1Connection to localhost closed by remote host.
2client_loop: send disconnect: Broken pipe
3Connection closed1# Modifiy sshd_config
2# ⚠️ It's sshd_config (with "d" after "ssh
3sudo nano /etc/ssh/sshd_config
4# At the end of the file
5Match User <username>
6 ChrootDirectory /Users/sftp-root/
7 ForceCommand internal-sftp
8 AllowTcpForwarding no
9
10# Then restart SSH
11sudo launchctl stop com.openssh.sshd
12sudo launchctl start com.openssh.sshd
13
14# Test
15sftp localhost
16ls