Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # add "prisoner" in the jail you created before !!
  4. # USAGE : ./add-user.sh <username>
  5. # A password will be auto-generated with pwgen (sudo apt install pwgen)
  6.  
  7.  
  8. # Set your jail path correctly
  9. JAIL_PATH=/home/www/
  10.  
  11. USER=$1
  12.  
  13. # You can use any password generator you want, or set it manually (e.g PASS=$2)
  14. PASS=$(pwgen -Bsv 16 1)
  15.  
  16. if [ "x$USER" == "x" ]; then
  17. echo "you have to provide a user name"
  18. exit;
  19. fi
  20.  
  21. getent passwd $USER > /dev/null 2&>1
  22. if [ $? -eq 0 ]; then
  23. echo "user already exists";
  24. exit;
  25. fi
  26.  
  27. # All the steps below will have to be done for all users we want to chroot
  28. # Create new user and add it to the sshjailed group
  29. useradd -G sshjailed -d $JAIL_PATH/home/$USER -s /bin/bash -p $(openssl passwd -1 $PASS) $USER && \
  30. echo "Password : ${PASS}"
  31.  
  32. mkdir -p $JAIL_PATH/home/$USER
  33.  
  34. # create or update minimal '/etc/passwd' file for our chrooted environment
  35. cat /etc/passwd | grep $USER >> $JAIL_PATH/etc/passwd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement