Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

having a bit of a difficult time trying to create a folder under another user's /home/devuser1/pubic_html folder. I'm trying to avoid using sudo and looking for an alternative. The permissions on the said folder reads as:

drwxr-s--- 2 devuser1  www-data 4096 Apr 28 19:40 public_html

Alternatively, assuming I use the sudo prefix, what would be the implications be? I've read that it's bad practice to use sudo to make a folder. After the new folder is created, I'm still changing the ownership of it to the user in question. Example:

chown -vR devuser1:www-data /home/devuser1/public_html/$vhost
share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

su -u [username] mkdir /home/[username]/public_html/[folder_name] works fine. From what I can see the permissions and ownership is the same if I were to log in as the same user and create the folder under public_html.

share|improve this answer
    
When you run sudo -u USERNAME mkdir DIRNAME, you are executing the mkdir command as the user USERNAME. This isn't exactly equivalent to logging in as USERNAME, because logging in also implies setting environment variables and so on, but it's the part that matters, namely executing a process as a particular user. –  Gilles Apr 30 '13 at 0:49
    
In fedora su: invalid option -- 'u' –  krupal Sep 20 '13 at 14:15
    
Another way to do this in fedora? –  krupal Sep 20 '13 at 14:26
    
The correct syntax for su is actually su -c <command-string> <user>. You may then use the command su -c "mkdir DIRNAME" <username>. –  sebleblanc Mar 12 at 3:57
add comment

Given those permissions, only the owner of the directory or the super user can create subdirectories.

The only way that you could avoid use extra privileges to create the folder is change the ownership to yourself (with sudo), create the subdirectory and finally return the ownership to the owner, but doesn't look like a good solution to me.

share|improve this answer
    
yea, tough one this. This is a silly question, but what are my options? –  maGz Apr 28 '13 at 20:51
    
what about (as root) running the command as that user?: sudo -u devuser1 mkdir /home/devuser1/public_html/test. That's not the same as creating the folder with sudo is it? ls -al reveals: drwxr-sr-x 2 devuser1 www-data 4096 Apr 28 23:49 test –  maGz Apr 28 '13 at 22:02
    
Maybe I'm being naïve, but I don't really see any evil in create a folder with sudo as long as you change the ownership after that. –  RSFalcon7 Apr 28 '13 at 22:14
    
From what ls reveals on the contents of the user's public_html, it appears as though changing ownership is not required, maybe permissions though. –  maGz Apr 29 '13 at 6:31
    
I think I'm also being naïve in thinking this: I'm not creating the folder as su, instead I'm using it to authenticate myself as the user who is going to create the folder...does that make sense? –  maGz Apr 29 '13 at 6:34
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.