Let's say I have a user 'user1'. This user has a special directory which can be accessed by another user ('user2'): /home/user1/directory
How can I allow ssh/sftp access for user2 only to this directory? so when user2 connects to the server via SSH/SFTP the /home/user1/directory is opened and only this directory could be accessed. user2 must have all kind of permissions within this folder only.
I was thinking about granting 777 permissions to this folder and creating a bash script to redirect to the folder but I'm not sure if this is a correct way.
Please advise.