LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-18-2011, 12:47 PM   #1
sourdough
LQ Newbie
 
Registered: Sep 2011
Posts: 7

Rep: Reputation: Disabled
Post 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.
 
Old 09-18-2011, 12:56 PM   #2
Ian John Locke II
Member
 
Registered: Mar 2008
Location: /dev/null
Distribution: Slackware, Android, Slackware64
Posts: 130

Rep: Reputation: 17
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.
 
Old 09-18-2011, 07:52 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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
 
Old 09-19-2011, 11:54 AM   #4
sourdough
LQ Newbie
 
Registered: Sep 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
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 :-)
 
Old 09-19-2011, 08:42 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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.
 
Old 09-20-2011, 10:39 AM   #6
Ian John Locke II
Member
 
Registered: Mar 2008
Location: /dev/null
Distribution: Slackware, Android, Slackware64
Posts: 130

Rep: Reputation: 17
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.)
 
Old 09-20-2011, 12:45 PM   #7
sourdough
LQ Newbie
 
Registered: Sep 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
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... :-)

Last edited by sourdough; 09-20-2011 at 12:50 PM. Reason: aded PS statement
 
Old 09-20-2011, 07:33 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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'

Last edited by chrism01; 09-20-2011 at 07:36 PM.
 
Old 09-20-2011, 09:27 PM   #9
sourdough
LQ Newbie
 
Registered: Sep 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
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 :-)
 
Old 09-20-2011, 09:52 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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.
 
Old 09-21-2011, 03:25 AM   #11
sourdough
LQ Newbie
 
Registered: Sep 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
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 :-(
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How is Multi Server configured without /home_dir? NightSky Linux - Server 4 04-28-2010 04:39 PM
a very basic question hectorDUQUE Fedora 7 01-14-2010 01:29 PM
basic html question - download link to files on my webpage question Davno Linux - Server 5 12-25-2009 08:24 AM
adduser question adnanm *BSD 1 03-14-2007 07:08 PM
Another basic adduser question AndeAnderson Debian 5 10-26-2005 08:44 AM


All times are GMT -5. The time now is 06:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration