Interview Prep/Linux/Users, groups and access control

A contractor needs SFTP access to upload files to one directory and nothing else. How do you set that up?

IntermediateScenarioUsers, groups and access control
Answer

Situation read → Chrooted SFTP-only account.

What I'd do →

  1. sudo useradd -s /usr/sbin/nologin -G sftponly contractor1
  2. Prepare the chroot (must be root-owned and not group-writable):
sudo mkdir -p /sftp/contractor1/upload
sudo chown root:root /sftp/contractor1 && sudo chmod 755 /sftp/contractor1
sudo chown contractor1:contractor1 /sftp/contractor1/upload
  1. In /etc/ssh/sshd_config:
Match Group sftponly
    ChrootDirectory /sftp/%u
    ForceCommand internal-sftp
    AllowTcpForwarding no
    X11Forwarding no
  1. sshd -t && systemctl reload sshd, then test with sftp.

Why → internal-sftp needs no binaries inside the chroot, and ForceCommand blocks shell access.

Interview tip → The most common failure is chroot ownership; sshd refuses if the chroot path is writable by the user.

All Linux questions Roadmap: Linux

More on Users, groups and access control