Skip to content

Instantly share code, notes, and snippets.

@cejojohn
Last active August 12, 2016 12:46
Show Gist options
  • Save cejojohn/cb409bb3dc0896be2e025567889f7a34 to your computer and use it in GitHub Desktop.
Save cejojohn/cb409bb3dc0896be2e025567889f7a34 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Create SFTP User
## This script will create the account with read-only permissions which helps us to give the user download-only files. Along with that we give a directory "uploads" that is present inside the user's home and can be used for uploading whichis having read-write access for this user.
echo "========================================================================================================================"
echo " SFTP account creation. The home dir will be read-only, for write access the user should use "uploads" directory in home."
echo "========================================================================================================================"
# Input username and the number of days that the user will be active. Only enter the "username" and "number" of days.
echo "Enter username:"
read USER
echo "Enter the number of days you want the user to be active:"
read DAYS
# Create user with expiry and sftpusers group so that it is chrooted, and giving -M will restrict useradd from creating the homedir
useradd -e `date -d "$DAYS days" +"%Y-%m-%d"` -M -d /uploads -s /sbin/nologin -g sftpusers $USER
# Creating home directory
mkdir -p /sftp/$USER/uploads
chown $USER. /sftp/$USER/uploads
# Setting password
echo create password for $USER
passwd $USER
echo "User: $USER Created!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment