Score:0

Ubuntu 18.04 > VSFTPd, PAM_MySQL :: How to set users home directory based on table column?

cw flag

First, thanks for taking the time to view my silly questions :) I have a server running Ubuntu 18.04 LTS, and I need to allow multiple users to connect via ftp on separate home directories for Web FTP purposes, and I've ran into an issue that I can't find any answers to after a day of searching, so I'm throwing in the towel and asking for help.

I have the table ftp in my database, and inside of it is 4 columns; id, username, pass, and domain, domain being the focus of my question. I've gotten PAM_MySQL to work properly, but now I need to be able to set usernames separate from their home directories, hence the aforementioned domain column. See, the problem is that everywhere I've seen, VSFTPd uses the virtual user's username for the home directory which is fine in most circumstances, however I need to be able to have user user1 be able to access domain test.mydomain.com, but I also need user3 be able to access test.mydomain.com as well, hence why I can't set the username to the domain and be done with it because user1 and user3 both need seperate passwords.

I've seen on this Server Fault Question from 11 years ago that this person has found an answer, which included inline MySQL in the /etc/vsftpd.conf file, however when I try their solution, and input my database credentials I've found that the client is able to log in successfully, but FileZilla complains about a GnuTLS error -15 which in my experience means that a home directory is not set, and an FTP connection cannot continue; which is funny because when I run it on the command line, I get a clean output without any styling or warnings, and it should output that way in the configuration file but it for some reason just.. doesn't.

Here's a snippet of the code I grabbed from that Server Fault question in my own vsftpd.conf:

``export MYSQL_PWD=MYSQLPASSWORD; mysql -sN -uUSERNAME -h HOSTNAME DATABASE -e "SELECT domain FROM DATABASE.accounts WHERE username='user1'"``

And here's it's output on the command line:

/var/www/subdomains/test.mydomain.com

I can set it to that manually in the configuration, and it works no problem, so I guess it's just the inline MySQL

So, is there a way around this? And, I would grab logs but none of them seem to show the directory the virtual user is trying to access, so if you know of a command that can do that; I'll gladly post it's output.

/var/log/vsftpd.log shows nothing useful, just that the client was able to log in. journalctl -xe shows the following:

Jun 03 03:17:57 server-4 vsftpd[18039]: pam_unix(vsftpd:session): session opened for user user1 by (uid=0)
Jun 03 03:17:57 server-4 vsftpd[18039]: pam_systemd(vsftpd:session): Failed to get user data.
Jun 03 03:17:57 server-4 vsftpd[18039]: pam_systemd(vsftpd:session): Failed to get user data.
Jun 03 03:17:57 server-4 pam-script[18039]: can not stat /usr/share/libpam-script/pam_script_ses_close
Jun 03 03:17:57 server-4 vsftpd[18039]: pam_unix(vsftpd:session): session closed for user user1

I'm able to give any logs you need so shoot and maybe you'll score!

Thanks though, really. I sincerely appreciate you spending your time on my issues.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.