LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   CentOS (https://www.linuxquestions.org/questions/centos-111/)
-   -   Shell script - craete user/password/home dir (https://www.linuxquestions.org/questions/centos-111/shell-script-craete-user-password-home-dir-4175594570/)

robertkwild 12-01-2016 06:20 AM

Shell script - craete user/password/home dir
 
hi all,

i have created a 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 ie so it asks if its for a vfx ftp or local ftp and also so it appends a file eachtime with the username and password so incase someone forgets the password for thier ftp i can look at the file and tell them

many thanks,

rob

michaelk 12-01-2016 07:54 AM

You can use either command line arguments or use read to prompt for home and name. Although you can use a file to save names and passwords typically the standard procedure is to reset to some predefined password and force the user to change at login.

TB0ne 12-01-2016 08:07 AM

Quote:

Originally Posted by robertkwild (Post 5636622)
hi all,
i have created a 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 ie so it asks if its for a vfx ftp or local ftp and also so it appends a file eachtime with the username and password so incase someone forgets the password for thier ftp i can look at the file and tell them

This seems like a pattern for you:
http://www.linuxquestions.org/questi...se-4175592277/
http://www.linuxquestions.org/questi...rm-4175576984/
http://www.linuxquestions.org/questi...es-4175574055/
http://www.linuxquestions.org/questi...es-4175572502/

Please, don't just keep asking for scripts/handouts, without showing any effort on your part. There are MANY bash-scripting tutorials you can find, and have been directed to in the past, that you can reference to get started. We're happy to help you if you're stuck, but show what you've done first.

robertkwild 12-01-2016 05:17 PM

getting close -

#!/bin/bash
echo "Enter UserName:"
read user
echo "Enter Password:"
read passwd
echo "$user:$passwd" >> /ftp.txt
useradd $user -b /mnt/data/
echo $user:$passwd | chpasswd

robertkwild 12-02-2016 10:05 AM

i have made it to a T now -

#!/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

robertkwild 12-05-2016 04:32 AM

Code:

#!/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



All times are GMT -5. The time now is 07:16 AM.