Basic instructions on how to set up an SSH server on an Ubuntu 16.04/18.04 EC2 instance.

Step 1 – Create a New User

1
sudo adduser testuser

Step 2 – Create a Directory for File Transfers

1
2
3
4
sudo mkdir -p /var/sftp/uploads
sudo chown root:root /var/sftp
sudo chmod 755 /var/sftp
sudo chown testuser:testuser /var/sftp/uploads

Step 3 – Restrict Access to One Directory

Open the SSH server configuration file

1
sudo nano /etc/ssh/sshd_config

Add the following to the bottom of the file:

1
2
3
4
5
6
7
8
Match User testuser
ForceCommand internal-sftp
PasswordAuthentication yes
ChrootDirectory /var/sftp
PermitTunnel no
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no

Apply the configuration changes

1
sudo systemctl restart sshd

Step 4 – Verify the Configuration

Verify the user cannot via SSH

1
ssh testuser@localhost

Verify the user can connect via SFTP

1
sftp testuser@localhost