2

I am having below directory structure.

/DR/Sub/X1/...
       /X2/...
       /X3/...
       .......

I want to give acces permissions to user but in below manner, when ever i create new directory like X1,X2,X3 suppose i create X4 i want to create new user for this new directory which will only and only access /DR/Sub/X4/... directory.....i.e. new user for new directory how can i achieve this.

Thanks in advance..

Dipak
  • 43
  • 1
  • 5
  • additionally to the answers below (that i would suggest you) it depends on what you REALLY want to do. If you want the directories because of SSH users you can think about jailing them to a specific dir: http://www.googlehemsida.se/c/Ubuntu_-_Jail_user_to_folder - it really depends on your intention. See chroot / jail. – Wolfgang Feb 13 '14 at 10:25

2 Answers2

3

The following commands will create user X4 and (by default) group X4 and directory X4, and will limit access to directory X4 to user X4 exclusively.

sudo adduser X4
sudo mkdir X4
sudo chown X4:X4 X4
sudo chmod 0750 X4

Note that nothing will prevent X4 from rummaging around elsewhere on the file system. There is no way to prevent that. However, no one except X4 and root will be able to access directory X4.

zwets
  • 12,354
  • thanks , and if i want to provide some user name and password to access X4 by user X4 then how can i do that? – Dipak Feb 13 '14 at 10:19
  • Username is X4 (specified by "adduser X4" and password can be set by using the passwd utility: "passwd X4") – Wolfgang Feb 13 '14 at 10:21
  • OK thanks i will try it now and if i done i will let u know. – Dipak Feb 13 '14 at 10:23
0

You can just create user using sudo adduser username --home dir, where dir can be any directory.

For example sudo adduser X4 --home /DR/Sub/X4.

This will create user X4 and specified directory accessible only by X4.

c0rp
  • 9,820
  • 3
  • 38
  • 60
  • hi , i have created 2 users X3 and X4 but when i login using X3 it is accessing X4's directory – Dipak Feb 13 '14 at 10:44