I am wishing to automate adding SFTP users. My commands required are the following, taking for example adding the user ‘jason’:
useradd jason
passwd jason
mkdir /home/jason
chown root:jason /home/jason
chmod 775 /home/jason
usermod -d /home/jason jason
usermod -a -G sftp jason
mount --bind /srv/ftp/~jason /home/jason
How may I replace each name with a variable for BASH, and have it ask for password at the beginning so it may plug it in where it is required?
I will try to learn to do this on my own, my mental capacity is very limited right now..
Note that if your version of
passwddoesn’t support the--stdinoption, you’re going to need to use something likeexpectorautoexpect