Help with Bash Script

I was presented with a little task at work and need some help for the fastest and shortest way possible. Now I just got this job, so I'm kind of a newbie to this. The task is to set up a shell script that will read a username of the user to create from a text file with a list of usernames. For example, create a text file with usernames separated by commas. (I have a list of user names, that are on the system already). (I was going to copy paste them on a text file I created), then create the selected user and home directory and give the mSmith user the rights to read, write, and execute the home directory recursively. This is the only user on the list that will have these privileges. No other users should have access but the user you are creating. Any help on how I should set this up would be appreciated.

I'm not sure if I understood you correctly.. but here it goes:
Easiest way of passing usernames to create is to store them in a file, with one username per line, like this:

user1
user2
user3

Then you can run command like this, to create those users on the system and also create their home directories with proper rights:

while read user; do useradd -m -d /home/$user $user; done<usernames

No need to use script for such a simple task :slight_smile:

useradd should need root privilege.
If it needs a password ,what would be the command?

Lets say I have three users, jsmith, ajames,tclark. How would I go about giving jsmith full access when he logs in and the other two names just read privileges?

If you don't want to run it logged as root, you need to run it as a sudoer

while read user; do sudo /usr/sbin/useradd -m -d /home/$user $user; done <  usernames

Two questions:

"full access" of what? If you want jsmith to have extra privileges you add jsmith to the sudoer, specifying what commands [s]he can run or by adding the account to a group that have specific privileges.

"just read privileges" of what?
Every account created receives ownership of its directories and files. Depending of the default mask , `Others' might, or might not have read, write, or execute permissions to those files, or access to those directories.

Your compound question is too ambiguous. Elaborate.

I understand that each user created has ownership of his directories and files, but I need jsmith to have full access of the other 2 users dir/files, but the other 2 users cannot access jsmith's files or one anothers.

Add jsmith to the same groups than ajames and tclark, and change the permissions so that the groups can have the access you want.

usermod -G ajames,tclark jsmith

Will set secondary groups ajames and tclark to jsmith
Assuming that those are the primary groups for them (many distributions make the group the same that the login user)
A caveat is that it will remove from jsmith any other secondary groups that you don't include in the command.

gpasswd -a ajames jsmith

Will add group ajames to jsmith without removing the previous secondary groups. But you need to include one at a time.

groups ajames

Will show groups that ajames belongs to

Of course, the right permissions should be set for the groups to be able to access files

umask 027

Will give read and execute permissions to group, and none to others.

umask 007

Will give same permissions to group as to owner, and none to others.

The default mask for when you create a new user is found in the file

/etc/login.defs

Groups can be a powerful tool.

If you just want to give some privileges to jsmith to go around snooping in other users. Take a look at /etc/sudoers

#> visudo

Will allow to modify /etc/sudoers as root