Monday, December 15, 2008

Adding FTP Users to a Mediatemple (dv)

Posted by Brendan on 12/15 at 05:46 PM (5) CommentsPermalink

After going to some pains to set up additional FTP users on my (dv) for different domains, I finally came up with a script that I think will help you all out (in the case you need to grant someone access to a single folder underneath a website directory).

To use this script, you must have root access enabled and be logged in as root (or su’d). I do not know if sudo will work for this.

The script should be fairly straightfoward… if you have any problems, please post here…. although there shouldn’t be any as I extensively tested this.

And without further ado…

You need to create two files. ftpuser.sh and passwd.exp

ftpuser.sh

#!/bin/sh

#
# (mt) DV 3.0+ FTP User Creation Shell Script
# Author: Brendan Corcoran
# Site: www.brendancorcoran.com
#

vhostsdir=/var/www/vhosts/

echo 
"-----------------------------------------------"
echo "- (mt) DV 3.0+ FTP User Creation Shell Script -"
echo "-    This script must be run as root user!    -"
echo "-----------------------------------------------"
echo " "

echo -"Username:          "
read usern

echo -"Password:          "
read userp

echo -"Domain:            "
read userd

echo -"Subdomain:         "
read usersd

echo -"Access Path:       "
read userap

echo -"Parent User:       "
read userparent

echo -"Parent User ID:    "
grep "$userparent:" /etc/passwd cut -d: -f3

echo -"Verify Parent UID: "
read useruid

while : 
    do
        echo 
" "
        
echo "-----------------------------------------------------------"
        
echo "Please review the above info, are you sure this is correct?"
        
echo "UID's MUST MATCH OR FTP USER WILL NOT HAVE ANY PERMISSIONS "
        
echo "-----------------------------------------------------------"
        
echo " "
        
echo -"Please answer 'y' for Yes, 'n' for No:    "
        
read choice
        
        
case $choice in
            
"y") echo "Adding User $usern with uid $useruid and gid psacln..." ;
                /
usr/sbin/useradd -u $useruid --d $vhostsdir$userd$userap -g psacln -/bin/false $usern ;
                
                echo 
"Setting user's password to $userp..." ;
                ./
passwd.exp $usern $userp ;
                
                echo 
"Adding user to psacln group..." ;
                /
usr/sbin/usermod -g psacln  $usern ;
                
                if 
test $usersd "" then
                  
echo "Making sure $vhostsdir$userd$userap is chmod 0755..." ;
                  
chmod 0755 $vhostsdir$userd$userap ;
                
elif test $usersd != "" then
                  
echo "Making sure $vhostsdir$userd/subdomains/$usersd$userap is chmod 0755"
                  
chmod 0755 $vhostsdir$userd/subdomains/$usersd$userap ;
                
fi
                
                
echo "Granting user permissions to $vhostsdir$userd$userap..."
                
chown $usern:psacln $vhostsdir$userd$userap ;
                
                echo 
"Exiting..."
                
exit ;;
                
            
"n") echo "Good thing you checked! Ending program." ; exit ;;
            *) echo -
"You didn't enter 'y' or 'n', press any key and try again." read ;;
                    
        
esac
done 

passwd.exp

#!/usr/bin/expect -f 
#
# Small expect script to automate setting passwd
#

spawn passwd [lindex $argv 0]
set password [lindex $argv 1]
expect 
"password:"
send "$password\r"
expect "password:"
send "$password\r"
expect eof 

Place these two files inside any non web accessible folder, preferably one that is also only accessible as root.

I placed mine in my /var/www/vhosts/domain.com/private folder… you could place them in /root if you’d like. Wherever you prefer, to be honest.

Once you have them in the correct place, make sure you are logged in as root and run the ftpuser.sh file like so:

[root@domain folder]# ./ftpuser.sh 

And you will have to follow the instructions from there.

Here is an example:

Let’s say my domain name is sample.com and my domain user is sampleuser. I want to create an FTP user whose username is testuser with the password testpass in the /httpdocs/testuser directory. At the prompts I would enter:

Username:              testuser    
Password
:              testpass
Domain
:                sample.com
Access Path
:           /httpdocs/testuser 
Parent User
:           sampleuser
Parent User ID
:        10000 (THIS IS AUTOGENERATED)
Please Verify User ID:    10000 

If you answer ‘y’ at the prompt you will see some messages on the screen such as:

Adding User testuser with uid 10000 and gid psacln...
Setting users password to testpass...
spawn passwd testuser
Changing password 
for user testuser.
New 
UNIX password
Retype new UNIX password
passwdall authentication tokens updated successfully.
Adding user to psacln group...
Making sure /var/www/vhosts/sample.com/httpdocs/testuser is chmod 0755...
Granting user permissions to /var/www/vhosts/sample.com/httpdocs/testuser...
Exiting... 

That’s it. You’re done. You should be able to log in with that username/password to that domain and the user will have access to that folder only, but with the same permissions as the primary domain user.

Hope this helps ease the pain of typing in all those commands to set up something so simple.

For Mediatemple users, please see this thread for any discussion on the topic. This could obviously be adapted to any webhost, but I tailored this to my Mediatemple (dv) 3.5

Thursday, October 23, 2008

How to Switch Leopard Shell from bash to tcsh

Posted by Brendan on 10/23 at 03:57 PM (3) CommentsPermalink

Does anyone out there love tcsh (tc shell)? I do. A former co-worker of mine introduced me to tcsh and after getting used to it, I said to hell with bash! Unfortunately every version of OS X from 10.3+ has used bash as the default login shell.

If you want to change that, keep reading:

It used to be that you could use the Netinfo Manager to change your login shell quickly and painlessly, but that is no longer the case since the Netinfo database and just about all its buddies have been completely removed from OS X. SO, how do we change the default login shell?

  1. Go to Accounts under your System Preferences
  2. Click the lock to unlock it and enter your password
  3. Right Click (or CTRL + Click) your account in the left column and click “Advanced Options”
  4. In this window, click the dropdown where you see /bin/bash and select /bin/tcsh
  5. Click OK and exit the windows you opened. Make sure to click the lock on your way out!

Now you can open terminal and magically you will be using tcsh!

“Great, now I have no terminal coloring” I can already hear you muttering. Well I have a solution for that as well!

To get the colors back:

  1. Download this file tcshrc.txt and save it to your user directory (e.g. /Users/*username*/)
  2. Open a terminal window.
  3. Type “mv tcshrc.txt .tcshrc” (without quotes) and hit enter.
  4. Quit and re-open your shell.
  5. Test by typing “ls -la” or any command that normally uses coloring :)

I hope this helped anyone out there looking to do as I did!

Monday, October 20, 2008

EE and Spam

Posted by Brendan on 10/20 at 12:07 PM (1) CommentsPermalink

Not sure if anyone noticed, but there were a plethora of spam messages on my first blog post. I have since cleared them all out, but I was confused as to why they showed up.

I checked my template about 10 times and I had the EE “if captcha” tag and CAPTCHA codes. As it turns out, you must enable Captcha for comments for EACH weblog under Weblog Management. This seems like a glaring oversight in my opinion. If you enable captcha… it should be defaulted to ON for everything. Maybe this is a no-duh for EE-experts, but I found it quite confusing!

So, if your ExpressionEngine Captcha isn’t working on comments (but is working on everything else)... that’s why!

Monday, September 08, 2008

Getting Started (with ExpressionEngine)

Posted by Brendan on 09/08 at 03:32 AM Blogging • (0) CommentsPermalink

Here’s my first post with ExpressionEngine, which is powering the latest iteration (and hopefully all future iterations) of my personal website. In addition to ExpressionEngine, I’m using Mootools as my javascript library and my very own css framework (well, admittedly it is more of a baseline with some templating involved). I hope you’ll enjoy… and perhaps learn something new by looking around my code a bit.

I recently moved to California from Virginia and I wanted to create a new version of my website and “do things right” for myself for a change. I’ve noticed that all too often one’s personal website will get neglected in favor of a clients or a website that is more hobbyist in nature. This time around I am dedicating a not-so-minuscule amount of effort towards updating and maintaining this website. This is the start.

Page 1 of 1 pages