homepage Welcome to WebmasterWorld Guest from 23.22.173.58
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
Sharing an existing directory
Permission for multiple accounts to use same directory
GoNC



 
Msg#: 4666715 posted 8:42 am on Apr 29, 2014 (gmt 0)

I have an account with a directory full of images that are regularly changed by scripts in the account. I have another account, and I want its scripts to be able to add / delete images in that same directory.

Eg, main directory:

/home/example/www/images/

should be able to be modified by user "example" and user "new".

I set up a symlink from the new account to the main directory, ala:

ln -s /home/example/www/images/ /home/new/

and the scripts in /new/ can read the files in /example/www/images/, but can't upload new ones. FWIW, the permission for the main directory is 0777.

I should mention that there are 6 directories in /example/ that I really want to share.

Can I just make "new" a user for the existing "example" without any real problems? Eg:

# Add "new_username" to group "example"
usermod -aG example new_username

# Change permissions for each directory to be shared
cd /home/example/images/
umask 002
chmod -R 2777 /home/example/images/


If not, then what if I created /home/shared/ manually (not as an account), then symlink the directories in both /example/ and /new/ to it? Like so (I think):

# Create group
groupadd shared

# Setup username and password for new group
# (do I just make up a username and password here?)
useradd -d /home/shared/ -g shared -m shared_username
passwd shared_password

# Add /example/ as a user
useradd -d /home/shared/ -g shared example_username
passwd example_password

# Add /new/ as a user
useradd -d /home/shared/ -g shared new_username
passwd new_password

# Change group ownership
chown -R shared_username:shared /home/shared/

# Set group permission
chmod -R 2775 /home/shared/

# Symlink
ln -s /home/shared/www/images/ /home/example/
ln -s /home/shared/www/images/ /home/new/


I would much rather not have to create a separate directory, because that would mean a lot of script modifications to /example/; and, of course, the account's stats (storage and bandwidth) would be wrong. But, if it's the best option, it CAN be one.

If neither of these are good options, what's a better idea?

 

graeme_p

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4666715 posted 9:04 am on Apr 29, 2014 (gmt 0)

I have not checked the command lines, but the basic idea is correct: add the "new" user to the group that owns the directory. You may want to create a new group just for this so "new" can only access that directory not all that belong to the group "example".

GoNC



 
Msg#: 4666715 posted 9:34 am on Apr 29, 2014 (gmt 0)

Security really isn't an issue for me; I own the server, and all of the accounts on it belong to me. So short of preventing an accidental script error, I'm not too concerned about the accounts having permission to change one another.

Based on this, then, I'll be running:

# Add "new_username" to group "example"
# Note: the -a here is for "append", so new_username can modify files
# under both groups "example" and "new"
usermod -aG example new_username

# Change permissions for each directory to be shared
cd /home/example/images/
umask 002
chmod -R 2777 /home/example/images/

My only question about the above is with umask 002; since it doesn't specify a directory, am I changing it for the current directory, or what?

Will I need to run umask for each directory that I intend for "new" to be able to modify?

GoNC



 
Msg#: 4666715 posted 1:55 pm on May 1, 2014 (gmt 0)

Well, guys, I'm at a loss on why this still isn't working.

I SSHed in as root, and ran all of the above commands. Then, I uploaded a simple Perl script to /home/new/www/cgi-bin/:

#!/usr/bin/perl
use File::Copy;
copy("/home/new/www/images/santa.jpg", "/home/example/www/images/santa.jpg");
exit;

But it's not copying the image, and it's not giving an error; it just doesn't do it.

I've gone through several checks; in the script, I make sure that the image does exist before copying, I've added a die() statement, I've even added umask 002; after File::Copy. But nothing.

I also added a symlink under /new/ to /example/images/, then tried copying to the symlink, but that didn't work, either. I noticed, though, that when I'm FTP'ed in as "new" and try to open the symlink, I get an error that the file doesn't exist. I thought that this might be a limitation of Filezilla with symlinks in general, but then /www/ is a symlink for /public_html/ that works fine, so... I dunno.

Any suggestions? If not, this entire project is dead in the water.

bhukkel



 
Msg#: 4666715 posted 2:16 pm on May 1, 2014 (gmt 0)

umask is just a template of permissions. These permission are set when you create a new file or directory. With chmod you can change the permission afterwards.

ps if your entire project depends on this hire a prof.

GoNC



 
Msg#: 4666715 posted 10:45 pm on May 1, 2014 (gmt 0)

umask is just a template of permissions. These permission are set when you create a new file or directory. With chmod you can change the permission afterwards.

That's what I understood from the other thread on this, too. But if that's the case, why am I still not able to copy images over?

If the default umask is 0022, and I've change it to 002, shouldn't any image created by the /new/ directory be created with a permission of 2777? Instead, they're not being created at all, which makes me think that the problem is the permission of the /example/www/images/ directory, not umask.

Or, possibly an issue with /new/ not being in the /example/ group. How do I double-check that?


if your entire project depends on this hire a prof.

I would gladly do this, except for the fact that I can't seem to find anyone that knows what to do.

GoNC



 
Msg#: 4666715 posted 8:41 am on May 2, 2014 (gmt 0)

Update:

It was recommend that I chown the entire /home/example/ directory, as well as every subdirectory that I would like to share. Like so:

chown example.new /home/example/
chown example.new /home/example/www/
chown example.new /home/example/www/images/

When I did this to a test directory, though, it showed the Owner/Group as:

example/new

Now, since I added "new" to the "example" group earlier, this looks backwards to me. Why am I changing the group to new?

So before I go and mess up the entire /home/example/ directory, I'm hoping you guys can confirm... is this right?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved