Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # add "prisoner" in the jail you created before !!
- # USAGE : ./add-user.sh <username>
- # A password will be auto-generated with pwgen (sudo apt install pwgen)
- # Set your jail path correctly
- JAIL_PATH=/home/www/
- USER=$1
- # You can use any password generator you want, or set it manually (e.g PASS=$2)
- PASS=$(pwgen -Bsv 16 1)
- if [ "x$USER" == "x" ]; then
- echo "you have to provide a user name"
- exit;
- fi
- getent passwd $USER > /dev/null 2&>1
- if [ $? -eq 0 ]; then
- echo "user already exists";
- exit;
- fi
- # All the steps below will have to be done for all users we want to chroot
- # Create new user and add it to the sshjailed group
- useradd -G sshjailed -d $JAIL_PATH/home/$USER -s /bin/bash -p $(openssl passwd -1 $PASS) $USER && \
- echo "Password : ${PASS}"
- mkdir -p $JAIL_PATH/home/$USER
- # create or update minimal '/etc/passwd' file for our chrooted environment
- cat /etc/passwd | grep $USER >> $JAIL_PATH/etc/passwd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement