Thi Notes
AboutNotesBlogTopicsToolsReading
About|Sketches |Cooking |Cafe icon Support Thi
Notes

Create a local SFTP connection

Create a local SFTP connection

Anh-Thi Dinh
Web Dev
Backend
Skills
Create an SFTP connection on local machine to make tests.

Quickly create a SFTP connection to ~/

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'

Make a specific folder as the root of the SFTP connection

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 error
1Connection to localhost closed by remote host.
2client_loop: send disconnect: Broken pipe
3Connection closed
1# 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