sudo apt update
sudo apt install -y openssh-server
Enable and start service:
sudo systemctl enable ssh
sudo systemctl start ssh
sudo systemctl status ssh
sudo addgroup ssh
sudo addgroup sftp
your_user : full SSH + SFTPftpuser01 : SFTP-only# Full SSH access
sudo usermod -aG ssh your_user
# Create new SFTP-only user
sudo adduser ftpuser01
sudo usermod -aG sftp ftpuser01
!! Replace
your_userwith your actual username. !! Replaceftpuser01with your ftp username.
Backup config:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.$(date +%F).bk
Edit config:
sudo nano /etc/ssh/sshd_config
Add at the bottom:
# Allow only these groups to connect
AllowGroups ssh sftp
# Restrict SFTP group to SFTP-only
Match Group sftp
    ChrootDirectory /data01/sftp/%u
    ForceCommand internal-sftp
    X11Forwarding no
    AllowTcpForwarding no
!! Replace
/data01/sftp/%uwith your ChrootDirectory.
Notes:
AllowGroups ssh sftp : blocks all other users from logging in.ChrootDirectory : locks SFTP users inside /data01/sftp/sftp/<username>.root:root and non-writable.Prepare secure chroot for SFTP:
# Creates the directory path for the SFTP user
sudo mkdir -p /data01/sftp/ftpuser01/files
# -----------------------------------------------------------
# Set secure ownership and permissions for the chroot path.
# All parent directories must be owned by root and not writable by others.
# -----------------------------------------------------------
# Set ownership and permissions for the data01 directory
sudo chown root:root /data01
sudo chmod 755 /data01
# Set ownership/ permissions of the top-level chroot directory to root
sudo chown root:root /data01/sftp
sudo chmod 755 /data01/sftp
# Set ownership/ permissions of the user's home chroot directory to root
sudo chown root:root /data01/sftp/ftpuser01
sudo chmod 755 /data01/sftp/ftpuser01
# -----------------------------------------------------------
# Set ownership of the writable directory.
# The user can only upload files into this sub-folder.
# -----------------------------------------------------------
# Change the owner of the 'files' directory to the sftp user
sudo chown ftpuser01:sftp /data01/sftp/ftpuser01/files
# Give the user full permissions to read, write, and execute in their files folder
sudo chmod 775 /data01/sftp/ftpuser01/files
Result:
ftpuser01 jailed to /data01/sftp/ftpuser01/data01/sftp/ftpuser01/filessudo apt install -y ufw gufw
sudo ufw allow from 192.168.150.0/24 to any app SSH
sudo ufw enable
sudo ufw reload
sudo ufw status verbose
!! Replace
192.168.150.0/24with your actual ip range.
sudo systemctl restart ssh
sudo systemctl status ssh
For better terminal readability (SSH only, not SFTP):
cp ~/.bashrc ~/.bashrc.$(date +%F).bk
nano ~/.bashrc
# Uncomment:
force_color_prompt=yes
source ~/.bashrc
your_user : Full SSH shell + SFTP access.ftpuser01 : SFTP-only, jailed to /data01/sftp/ftpuser01/files.Open PowerShell or Command Prompt:
ssh your_user@192.168.150.10
sftp ftpuser01@192.168.150.10
WinSCP : Free, popular for SFTP/FTP/SSH.
192.168.150.10ftpuser01SFTPFileZilla : Supports SFTP too.
sftp://192.168.150.10ftpuser0122