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 →
sudo useradd -s /usr/sbin/nologin -G sftponly contractor1- 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
- In
/etc/ssh/sshd_config:
Match Group sftponly
ChrootDirectory /sftp/%u
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
sshd -t && systemctl reload sshd, then test withsftp.
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.
More on Users, groups and access control
You need to onboard 50 new developers onto a shared build server, each with their own account and SSH key. How do you do it?BeginnerThree teams share one server and each needs a project directory only its members can write to, with new files staying group-owned. How do you set it up?BeginnerA junior engineer needs to restart nginx but must not get full root. How do you grant that?BeginnerAn engineer leaves the company today. What do you do with their Linux account on 30 servers?BeginnerA service account for a backup tool must exist on every server but nobody should be able to log in as it. How do you create it?BeginnerYour security team requires passwords to expire every 90 days for human users only. How do you implement it?Beginner