Setting a user's home directory only determines the directory where they are by default. Users can see the rest of the filesystem.
If you want an account to be restricted to file transfer and to only have access to a specific directory tree, you need to “jail” that user. This is supported natively by OpenSSH; for example, if you put those friends (and only them) in the friends
group:
Match Group friends
ForceCommand internal-sftp
ChrootDirectory %h
#AuthorizedKeysFile /etc/sshd/friends/%u.authorized_keys
The ChrootDirectory
confines these users to their home directory. If they all have the same home directory, they'll all be able to use the same SSH keys, which may not be what you want. Uncomment the AuthorizedKeysFile
line if you don't want these users to be able to upload their own authorized keys.
If you want to treat these users independently from an authentication point of view, don't want them to be able to manipulate their keys, and want to give them all access to the same directory tree, then you can set a particular directory instead:
Match Group friends
ForceCommand internal-sftp
ChrootDirectory /pub
If you want to give these users access to multiple parts of the filesystem, you can make a combined view using a bind mount.
ForceCommand internal-sftp
restricts these users to SFTP access (e.g. with Filezilla or over SSHFS). If you want to allow other methods such as rsync, you need a fancier configuration, e.g. using rssh (read the CHROOT guide).