Ubuntu – OpenSSH – Restrict users to one or multiple folders

directorygroupsopensshpermissions

I want to know how I can restrict user access using OpenSSH Server.
Let's say I want

  • user 1 to only access /Media, /Documents, and his home folder,
  • User 2 should only access /Folder21, and his homefolder,
  • User 3 should only have access to /Documents, /Folder21 and his home folder,

How can I do such a thing?

I found how to do it with one folder, but that was for all users, I think?
description here: https://bensmann.no/restrict-sftp-users-to-home-folder/

(copied from link I gave above:
Can I just do this:

$ usermod User1 -s /bin/false
$ usermod User2 -s /bin/false

And set the user’s home directory:

$ usermod User1 -d /folder
$ usermod User2 -d /folder

then make all the other folders subfolders of /folder, and restrict access to those folders accordingly to my wishes using the chmod command, or is there a better solution??

Addition and clarification:
Adding it to their homedirectory is not an option, as it are shared folders, some users need access to the same content,while it is restricted to other users,

This is what I had in mind:

  • user 1
  • user 2
  • user 3
  • user 4

  • folder "Network documentation"

  • folder "application documentation"
  • folder "Downloads"
  • folder "Media"

  • User 1 needs full access to everything, but Read-only access to application documentation List item

  • User 2 needs full access to both documentation folders
  • User 3 only needs access to the "Media" folder
  • User 4 only needs access to the folder "Downloads" and "Application Documentation"

Best Answer

Could you not just put whatever folders you want each user to access in their home directory? If not, I believe that ssh uses the same file permissions as the file system on the computer. So you can just use the same file permissions modifiers you would use to give a user access to a folder outside their home directory, like this: https://superuser.com/questions/280994/give-write-permissions-to-multiple-users-on-a-folder-in-ubuntu

Related Question