LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
Password
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.

Notices


Reply
  Search this Thread
Old 12-01-2016, 06:20 AM   #1
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Rep: Reputation: Disabled
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
 
Old 12-01-2016, 07:54 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,722

Rep: Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916
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.
 
Old 12-01-2016, 08:07 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,647

Rep: Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969
Quote:
Originally Posted by robertkwild View Post
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.

Last edited by TB0ne; 12-01-2016 at 08:09 AM.
 
Old 12-01-2016, 05:17 PM   #4
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
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
 
Old 12-02-2016, 10:05 AM   #5
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
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
 
Old 12-05-2016, 04:32 AM   #6
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Starting shell dir when home dir is a symlink oryan_dunn Linux - General 7 03-14-2014 01:16 PM
create a directory at user home using shell script nagendrar Solaris / OpenSolaris 10 04-30-2010 05:30 AM
logoff script remove home DIR & user profile sportivo888 Linux - Newbie 3 12-09-2007 03:30 AM
Can my shell script change the password of user ? prabhatsoni Linux - Software 1 05-27-2006 02:06 AM
how to assign password for a user in shell script mtest Programming 10 10-29-2003 06:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 12:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration