Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Adding users to linux and adding to an existing group

    Good day all,

    I've been asked by my professor to add the list of users to a linux server (not sure of the OS type i think he said debian) but anyway.....he gave me this script to add users.....

    # Script to add a user to Linux system
    if [ $(id -u) -eq 0 ]; then
    	read -p "Enter username : " username
    	read -s -p "Enter password : " password
    	egrep "^$username" /etc/passwd >/dev/null
    	if [ $? -eq 0 ]; then
    		echo "$username exists!"
    		exit 1
    		pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
    		useradd -m -p $pass $username
    		[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
    	echo "Only root may add a user to the system"
    	exit 2

    I need to see if i can get this script to read a file that list the usernames and their passwords using the pipe command (or some similar command) so i can just do it in one batch. i've done some searching but there are so many vairiations of the code that i've confused myself.

    Also, i'm not too familiar with linux, it's been a few years since i've used it but in the prior script, i need to add the users to an existing group named "forensics". Which line would i change/add in order to do this?

    Forgive me if this topic has already been posted.

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Nottingham, England
    Good luck with solving this. I'm pretty sure that bash scripting is covered really well on the Internet - you can Google lots of assistance.

    Unfortunately, asking homework questions on this forum is not allowed. Some may be willing to help, though - perhaps if you had a stab at a solution and asked specific questions about what doesn't then work?
    Linux user #126863 - see

  3. #3
    I beg your pardon Roxoff, but this is not a home work assignment. i am working with the teacher to set up a linux server so the students can access it and be added to a group. Also, i don't see how i can explain any clearer what questions i asked.

  4. $spacer_open
  5. #4
    Here is a pretty good bash scripting guide.

    Also, check the man page for useradd for the line to see what you need to do as far as groups go.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts