#!/bin/bash # jailuser # A quick and dirty hack of a script for jailing users. # Copyright 2007, 2008 Daniel Bartholomew ############################################################################### # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . ############################################################################### # Jailkit _must_ be installed for this script to work! Even then it may not. # You can download jailkit from: http://olivier.sessink.nl/jailkit/ # Some test variables #company=testcompany #passwd=test #user=testuser # you shouldn't need to add the company group, since the mkjail script # should have done it for you #groupadd ${company} # Some default variables jailp="/home/jail" # Path to the jails skelp="/etc/skel-jail" # Path to the jail skeleton dir # Set skelp to /etc/skel if in doubt # The script should be run with a three arguments following, which should be: # (1) the name of the company whose jail you are adding the user to, # (2) the username you are adding, and (3) the password of said user. company=${1} user=${2} passwd=${3} function USAGE { echo echo "Usage: ${0} company_name user_name password" echo echo "Example: ${0} widgetworld wwuser1 wwpassword" echo echo return } if [ -z ${company} ] || [ -z ${user} ] || [ -z ${passwd} ]; then # If the required arguments were not supplied, then we quit after # printing out the USAGE message. echo echo echo "You did not enter in all of the required objects." echo USAGE echo exit 1 else # If we get to this point, we have our three variables so we're good to go. # First, we add the user, just like we would a normal user... echo "Adding user '${user}'..." useradd -g ${company} -m -k ${skelp} ${user} # Then we set the password for the user using the 'chpasswd' command... echo "...with password '${passwd}'..." echo ${user}:${passwd} | chpasswd # This is the command that does the heavy lifting echo "...to the '${company}' jail..." jk_jailuser -m -n -j "${jailp}/${company}" ${user} fi # I should probably mention that this script ignores any arguments after the # first three that it sees. Maybe we should complain to the user if there are # more than three, but for now . . . this is good enough. # And now we're... echo "Done."