Created
May 24, 2014 18:29
-
-
Save d4rkcat/cddd70c423d1d5ee667a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $(whoami) != 'root' ] 2> /dev/null;then | |
echo ' [X] Need r00t!' | |
exit | |
fi | |
if [ $(cat /etc/group | grep sftpusers) -z ] 2> /dev/null;then | |
groupadd sftpusers | |
fi | |
if [ $(cat /etc/ssh/sshd_config | grep 'Match Group sftpusers') -z ] 2> /dev/null;then | |
sed -i 's/^Subsystem/#Subsystem/g' /etc/ssh/sshd_config | |
echo -e "\n#Setup for chroot sftpusers\n\nSubsystem sftp internal-sftp\nMatch Group sftpusers\n\tChrootDirectory /sftp/%u\n\tForceCommand internal-sftp" | |
fi | |
read -p ' [>] Enter the name for the user: ' SUSER | |
if [ $(cat /etc/passwd | grep $SUSER) -z ] 2> /dev/null;then | |
echo " [*] user $SUSER ok." | |
echo | |
else | |
echo " [X] user $SUSER already exists." | |
exit | |
fi | |
useradd -g sftpusers -d /incoming -s /sbin/nologin $SUSER | |
echo -e " [>] Enter the password for $SUSER:\n" | |
passwd $SUSER | |
mkdir -p /sftp | |
mkdir -p /sftp/$SUSER | |
mkdir -p /sftp/$SUSER/incoming | |
chown $SUSER:sftpusers /sftp/$SUSER/incoming | |
service ssh restart | |
echo -e "\n [>] All done, user $SUSER added to chroot jail at /sftp/$SUSER" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment