简体   繁体   English

限制用户访问linux / ubuntu中的特定目录

[英]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. 我想建立一个在线的UNIX辅导老师,任何用户(主要是学生)都可以来实践UNIX命令。

User needs to login to webpage and they'll have direct access (from webpage ) to 'user' directory on ubuntu server 用户需要登录到网页,并且可以直接从ubuntu服务器访问(从网页)到“用户”目录

eg For 'USER-1' his working directory will be set to : /home/ubuntu/user-1/ 例如,对于“ USER-1”,其工作目录将设置为:/ 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/ 对于“ USER-2”,其工作目录将设置为:/ home / ubuntu / user-2 /依此类推..直到/ home / ubuntu / user-n /

Now the issue is I want that user should be able to run command only within his directory ie '/home/ubuntu/user-1/' he cannot move to parent directory or any other system directory, only child directorys are allowed with rw access. 现在的问题是我希望用户只能在他的目录中运行命令,即“ / home / ubuntu / user-1 /”,他不能移动到父目录或任何其他系统目录,只有子目录被允许通过rw访问。

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-* /

/home/ubuntu/user-1/ : user-1 can access Only this directory / home / ubuntu / user-1 /:user-1只能访问此目录
/home/ubuntu/user-2/ : user-2 can access Only this directory / home / ubuntu / user-2 /:用户2只能访问此目录
.
.
.
/home/ubuntu/user-n/ : user-n can access Only this directory / home / ubuntu / user-n /:user-n只能访问此目录

I'm new to unix, any idea on how I can go about it? 我是unix的新手,对如何使用它有任何想法吗?

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. 问题是您将使用相同的用户帐户执行每个Unix命令,并且如果您不提供其他信息,Unix将无法知道用户何时有权访问目录或否。

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. 这是一种使用2个用户的方法:从另一个帐户中,您将必须创建users目录,每次用户执行命令时,您都将从第一个帐户中执行此操作:chmod 600 / home / ubuntu / user- * && chmod 664 user-n并且您从第二个用户执行每个命令,因此他将只能访问user-n目录。

But a much more cleaner way would be to have a user for a home directory on the server. 但是更干净的方法是在服务器上拥有一个主目录用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM