LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   adduser basic (home_dir) question (https://www.linuxquestions.org/questions/linux-newbie-8/adduser-basic-home_dir-question-903688/)

sourdough 09-18-2011 11:47 AM

adduser basic (home_dir) question
 
I know this question is probably common knowledge but that page is missing from my mind.

In all of the Linux adduser examples I've seen the home_dir value is shown as "-d /home/user"

But -- how do I set the home_dir value to an actual website folder?

NOTE: I'm using a commercial VPS Linux Server account with full root access.

for example -- how do I set the home_dir value to a real working website directory such as httpdocs/mywebsite.com/userFolder

BTW: I can not find my website directory tree in the "root" /home/ directory....

Any help would be appreciated.

Ian John Locke II 09-18-2011 11:56 AM

It depends on where httpdocs is. If it is
/home/youruser/httpdocs/...
Then you will have to use that full path.
If it is elsewhere like
/var/www/httpdocs
Then that is the path. Idk, if you can do that in the first case though. I can test it later. But the full path is what is important. Has to start with root (/) and follow the directories to the folder you want.

chrism01 09-18-2011 06:52 PM

Can I ask why you are doing this? I've never come across that approach before (ie putting a home dir inside a web dir tree).
If you want the user to be able to host web pages in his home dir area, then usually you create a/home/user/public_html dir and use the UserDir directive in the Apache httpd.conf.
See this page for a HOWTO https://httpd.apache.org/docs/2.2/mod/mod_userdir.html

sourdough 09-19-2011 10:54 AM

Thanks Ian -- your suggestion about /var/www/httpdocs helped me figure out how to use mkdir in a local website context.

chrism01 -- What I'm trying to figure out is how to use scripting (PHP) to create new users "on the fly" -- complete with user name and password and also create a new user area (restricted folder) -- for each "client" that logs into my website.

This endeavor is proving quite difficult because I have no Linux background and I'm not familiar with any of the Linux syntax or commands. Everything is a completely new learning experience. For example -- all of the code I've seen showing how to use mkdir is from the "root" perspective /home/user... But I wanted to use mkdir from my website perspective -- (i.e. mkdir mywebsite.com/newfolder). The difficulty I had was that I'm using a VPS server and "mywebsite" is created in a Plesk control panel -- so I could not find any way to connect the "root" directory to my Plesk website. Using Ian's suggestion I found I was able to ignore the "root" directory and just use the mkdir command in a "local" context.

The actual PHP command looks like.

Code:

<?php

/* creates folder in the current website directory*/
@exec("echo 'apache' | /usr/bin/sudo mkdir newfolder");

/* creates folder in a different website directory */
@exec("echo 'apache' | /usr/bin/sudo mkdir ../othersite.com/newfolder");

?>

I was able to figure out how to use the Linux adduser command -- now I need figure out how to create valid passwords for a user.... and that's proving difficult because it seems I need to (somehow) programmatically enter the password twice using the passwd command.

Any help about creating a user password (in a script) would be appreciated :-)

chrism01 09-19-2011 07:42 PM

You probably need something like phpsuexec http://www.webhostingtalk.com/showthread.php?t=404385.
If you are creating Linux users ie new users for the OS, then their home dirs should NOT be inside the web servers Document root.
As for passing passwd on the cmd line, use the --stdin option http://stackoverflow.com/questions/7...a-shell-script http://linux.die.net/man/1/passwd

some good shell (bash) tutorials

http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

I also suggest you find out which distro you have
Code:

uname -a

cat *release*

and start reading the relevant manual(s) at www.linuxtopia.org.

Ian John Locke II 09-20-2011 09:39 AM

If you wanted to do it the hackish way you could do useradd and then modify /etc/shadow, /etc/group and /etc/passwd to do it without needing the interactive adduser.

This is fairly dangerous though (or can be if your input isn't properly sanitized (like anything that takes user input and performs system calls with it.)

sourdough 09-20-2011 11:45 AM

Thanks for the input and suggestions..

chrism01-> from your uname -a code I got "2.6.18-028stab091.2 #1 SMP Fri Jun 3 00:02:04 MSD 2011 x86 64 GNU/Linux" and for my VPS Panel I got .debian-5.0-x86_64 -- I couldn't get anything from your code cat *release* code. Do these help?

BTW: My "new users" -- I'm trying to setup each new user with a restricted folder on my web site. Theadduser and passwords will only be used to create an FTP account for each user so they can use an FTP program (cuteFTP) to upload/download the files. Ideally It would be nice if I could use FTP commands to create the username and password values -- but I can find out how to do that.

Therefore the steps would be 1) Create a "username" folder on my web site (i.e. mywebsite.com/userfolder) 2) use adduser to create a username entry in the system. 3) use passwd to enter passwords for the user in the system. 4) use chroot to restrict the user to his "restricted" folder. 5) send the user his FTP login credentials so he can FTP his files to the "restricted" folder.

I think, by running the above steps from a PHP program on my server, the username and passwords generation should be quite secure (they won't show up in a browser).

Ian-> You message is quite intriguing -- but exactly how would I go about modifying /etc/shadow, /etc/group and /etc/passwd values. DO you have a link showing the procedure? I'm not sure what you mean by "sanitizing". Can you please explain or provide a link to the information?

PS.. Perhaps the steps I've outlined to create "restricted" FTP accounts could be done a better way -- any comments or suggestions would be appreciated... :-)

chrism01 09-20-2011 06:33 PM

Try posts 4 & 5 here http://www.linuxforums.org/forum/red...unt-vsftp.html
Your requirements make more sense now you've specified FTP only accts.

BTW, your VPS says you've got Debian, so checkout the manuals for Debian here http://www.linuxtopia.org/online_boo...ion_index.html

Hopefully a Debian guru will drop by as well. You could try amending the thread title to include 'Debian' and 'ftp only'

sourdough 09-20-2011 08:27 PM

Debian... "ftp only"
 
chrism01 > Thanks for the input -- and the links..

I've checked around and found instructions for using vsftpd (adding chown etc.) but everything I've seen seems to say I still need to add a user to the Linux "root" system with the adduser command and add a system password using the passwd command. -- Adding a user with scripting is pretty straight forward but adding a password via scripting is proving difficult (or maybe impossible).

One solution I ran across involved using the "cat" command to modify the /etc/passwd and etc/shadow files. I haven't figured out how to do that yet. However I was able to add "test" user data to a "test" passwd file using "cat" -- everything looks OK....

I also ran across information stating that the passwd system first adds the username to it's log and then enters an "x" value indicating the users password is installed in the shadow file. (It seems before the "shadow" system was adopted that the "x" position contained the users password).

Do you (or anyone else) know if the "x" value in the passwd file was replaced with an actual "unencrypted" password (i.e. "12345") that the system would use that password for the user? It may be easier to replace "x" with a password than trying to add an encrypted password to the "shadow" file that is "acceptable" to the Linux system.

BTW: I couldn't find a way to include "Debian" or "ftp only" to this post -- except as a title :-)

chrism01 09-20-2011 08:52 PM

You set the passwd in a script using the --stdin option as per my post #5.
DON'T try to put a passwd in /etc/passwd, as this is a world readable file; which is why /etc/shadow was created years ago.

sourdough 09-21-2011 02:25 AM

chrism01 > I understand the concern about putting a password in /etc/passwd -- but I'm just trying to find some way to make this work.

I tried for hours to get the code in your #5 post to work in a PHP script but I finally had to give up. I just do not have competence to make it work (or figure out if it's even capable of working). I don't even know what scripting language that code was designed to operate in or if it can be ported to PHP.

To use Linux commands in PHP I have to enclose them in a PHP "exec" or "shell_exec" function call -- for example...

Code:

<?php

//echo exec("whoami"); // shows the current user ID
//shell_exec('sudo mkdir -m 755 userFolder') // creates a userFolder in the current directory ans sets mode to 755

$var = shell_exec("ls -1 /etc/passwd"); // execute command to view passwd data
echo $var; // shows the output of the ls -l command

?>

Therefore unless I can find a way to use your #5 post code -- I'm kind of stuck :-(


All times are GMT -5. The time now is 10:41 PM.