Guest User

Untitled

a guest
Aug 31st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # change username and password here:
  4. username="user"
  5. password="user"
  6.  
  7. # create groups
  8. groupadd sftp
  9.  
  10. # create chrooted user
  11. useradd -m $username -G sftp
  12. echo $username:$password | chpasswd
  13.  
  14. # enable password authentication in sshd
  15. cp /etc/ssh/sshd_config /etc/ssh/sshd_config.before_chroot
  16. cat /etc/ssh/sshd_config | sed -e "s/PasswordAuthentication no/PasswordAuthentication yes/" > /etc/ssh/temp_sshd_config
  17. mv -f /etc/ssh/temp_sshd_config /etc/ssh/sshd_config
  18.  
  19. # disable default sftp subsystem configuration in sshd
  20. sed -e '/Subsystem sftp/ s/^#*/#/' -i /etc/ssh/sshd_config
  21.  
  22. # add sftp subsystem configuration to sshd
  23. echo "Subsystem sftp internal-sftp" >> /etc/ssh/sshd_config
  24. echo "Match Group sftp" >> /etc/ssh/sshd_config
  25. echo " ChrootDirectory %h" >> /etc/ssh/sshd_config
  26. echo " AllowTcpForwarding no" >> /etc/ssh/sshd_config
  27.  
  28. # restart ssh service
  29. #/etc/init.d/sshd restart
  30. systemctl restart sshd
  31.  
  32. # create the chrooted directory structure
  33. mkdir /home/$username/bin
  34. mkdir /home/$username/dir
  35. mkdir /home/$username/usr
  36. mkdir /home/$username/usr/bin
  37. mkdir /home/$username/usr/lib64
  38. mkdir /home/$username/usr/libexec
  39. mkdir /home/$username/lib/
  40. mkdir /home/$username/lib64
  41. mkdir /home/$username/etc
  42. mkdir /home/$username/dev
  43. mkdir /home/$username/dev/pts
  44.  
  45. # create non-files
  46. mknod -m 666 /home/$username/dev/null c 1 3
  47. mknod -m 666 /home/$username/dev/tty c 5 0
  48. mknod -m 666 /home/$username/dev/zero c 1 5
  49. mknod -m 666 /home/$username/dev/random c 1 8
  50. mount --bind /dev/pts /home/$username/dev/pts
  51.  
  52. # get the directory permissions right
  53. chown $username.$username /home/$username/. -R
  54. chmod 0755 /home/$username/bin
  55. chmod 0666 /home/$username/.bashrc
  56. chown root.root /home/$username
  57. chmod 0755 /home/$username
Add Comment
Please, Sign In to add comment