Register
It is currently Tue Dec 12, 2017 12:00 pm

shell script - craete user/password/home dir


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Thu Dec 01, 2016 5:25 am   

Joined: Tue Apr 12, 2016 4:11 am
Posts: 51
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


Top
 Profile  
 PostPosted: Thu Dec 01, 2016 10:38 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 560
Code:
user=someone

read -p "Create local or NFS User? Default: l  l|n : " account_type
# do some checks here

read -s -p  "Enter password : " password

# append data to a file
# you know that this is a very stupid idea?
echo user:$user account_type:$account_type password:$password  >> stupid_insecure_password_file


Top
 Profile  
 PostPosted: Thu Dec 01, 2016 5:19 pm   

Joined: Tue Apr 12, 2016 4:11 am
Posts: 51
getting close -

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


Top
 Profile  
 PostPosted: Fri Dec 02, 2016 10:02 am   

Joined: Tue Apr 12, 2016 4:11 am
Posts: 51
i have made it to a T now -

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
  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


Top
 Profile  
 PostPosted: Mon Dec 05, 2016 4:30 am   

Joined: Tue Apr 12, 2016 4:11 am
Posts: 51
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


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP