Wednesday, July 21, 2010

that was fun.

Wrote a shell script for work. Don't do that enough. Could have been done a million and one ways, but I did it this way (see below).

The itch:
Person who maintains the FTP server's user accounts is not a GNU/Linux person. She's asked for help and simplicity in the past for creating user accounts. Need to create the user, the home directory, set the password and set file permissions and file acl permissions.

The solution (slightly modified):
#!/bin/bash
# program to create new ftp users. Creates directory, sets permissions and ACL. Will ask for password.
# password section for Redhat Based systems

# get user name from command line

if [ -z "$1" ]
then
echo "$0: Usage: $0 user-name "
exit 3
fi
name="$1"

# create user account, and directory
useradd -d /FTPDIR/"$name" -s /bin/bash -g 502 "$name"

# get new password for user
echo "enter password for user $name"
read user_password
echo $user_password | passwd --stdin $name

# change ownership of directory
chmod 777 /FTPDIR/"$name"

# set acls for directories
setfacl -R --set u::rwx,g::rwx,o::rwx /FTPDIR/"$name"
setfacl -d -R --set u::rwx,g::rwx,o::rwx /FTPDIR/"$name"

# let user know it's done
echo -e "\n User $name is ready to log in. \n"

No comments: