Hemanshu Belani
Hemanshu Belani

Reputation: 319

Restrict user access to a particular directory in linux/ubuntu

I want to build an online unix tutor wherein any user (mostly students) can come and practise unix commands.

User needs to login to webpage and they'll have direct access (from webpage ) to 'user' directory on ubuntu server

e.g. For 'USER-1' his working directory will be set to : /home/ubuntu/user-1/

For 'USER-2' his working directory will be set to : /home/ubuntu/user-2/ and so on.. till /home/ubuntu/user-n/

Now the issue is I want that user should be able to run command only within his directory i.e. '/home/ubuntu/user-1/' he cannot move to parent directory or any other system directory, only child directorys are allowed with rw access.

I read some articles on restricting access to user, all those articles pointed to creating a user account with restricted access.

However I want to create a single account having different users directory with restricted access.

After a user login on webpage his working directory will be set to : /home/ubuntu/user-*/

/home/ubuntu/user-1/ : user-1 can access Only this directory
/home/ubuntu/user-2/ : user-2 can access Only this directory
.
.
.
/home/ubuntu/user-n/ : user-n can access Only this directory

I'm new to unix, any idea on how I can go about it?

Upvotes: 0

Views: 3358

Answers (1)

jjacobi
jjacobi

Reputation: 405

The problem is that you will execute every Unix command from the same user account and if you don't give other information Unix won't be able to know when the user have the right to access a directory or no.

This is a way to do it with 2 users : From another account you will have to create the users directories, every time a user execute a command you do this from the first account : chmod 600 /home/ubuntu/user-* && chmod 664 user-n And you execute every command from the second user so he only will have access to the user-n directory.

But a much more cleaner way would be to have a user for a home directory on the server.

Upvotes: 1

Related Questions