I have created an ftps server using vsftpd and it works a treat
atm to create a user/password/home dir I do these two command -
useradd test -d /mnt/data/test
passwd test
also I have another dir that I use for home dirs, which is using a nfs location (vfx_ftp) and not the local sdb1 (data)
useradd test1 -d /mnt/vfx_ftp/test1
passwd test1
How can I make this into a script i.e. so it asks if its for a vfx ftp or local ftp and also so it appends a file each time with the username and password so in case someone forgets the password for their ftp I can look at the file and tell them
cant the script ask if you want it to be a vfx ftp (mounted on nfs share) or a data ftp (mounted on local sdb1 drive)?
and then from there it will ask you to enter a username and password and from the above question the home dir will be what you selected ie data mount or vfx mount
It can indeed, I was assuming that you needed an automatic way to work it out. A few questions, if I may:-
What shell are you using? (the output from echo $SHELL would be fine)
What OS version are you using? (the output from uname -a would be very useful here)
What have you tried?
I ask the last question because it is better for us to know your style and adjust it rather than to impose a solution that you cannot understand or support.
Please post all code, files, input & output/errors in CODE tags. It makes it far easier to read.
#!/bin/bash
echo "Enter UserName:"
read user
if id $user ; then
echo "$user already exists as you can see above, please re-run the script"
exit
else
echo "$user not in system, ok to continue"
fi
echo "Enter Password:"
read passwd
echo "$user:$passwd" >> /ftp_details/accounts.csv
useradd $user -s /sbin/nologin -b /mnt/data/
touch /mnt/data/$user/files_will_get_deleted_older_than_14_days_old.txt
echo $user:$passwd | chpasswd
You are getting there. Ask your user if they are a vxf or normal user, read in the reply then using an if set a variable for the home directory. You can then use this variable in the useradd command.
#!/bin/bash
echo "Enter UserName:"
read user
if id $user ; then
echo "$user already exists as you can see above, please re-run the script"
exit
else
echo "$user not in system, ok to continue"
fi
echo "Enter Password:"
read passwd
echo "$user:$passwd" >> /ftp_details/accounts.csv
echo "is this a normal user (1) or vfx user (2) ?"
read dir
case $dir in
1)
useradd $user -s /sbin/nologin -b /mnt/data/
touch /mnt/data/$user/files_will_get_deleted_older_than_14_days_old.txt
;;
2)
useradd $user -s /sbin/nologin -b /mnt/vfx/
;;
esac
echo $user:$passwd | chpasswd