Jump to content

Linux (ubuntu/bash) script to add users manually

Go to solution Solved by Jade,
18 minutes ago, aurrorax said:

I have found this aswel, unfortunately I am not allowed to use adduser or useradd , newusers is allowed.

Should be easy enough, then. Here's the manpage for newusers -- not gonna do all your work. ;)

This code is untested and I can't be held liable for it, all that legal stuffs.

How to run the script:

./myUserScript thisListOfImportedUsers

What's in the script, theoretically. $1 is variable 1 (argument -- thisListOfImportedUsers)

#!/bin/bash

newusers $1

What's in thisListOfImportedUsers - formatted as 

<Username>:<Password>:<UID>:<GID>:<User Info>:<Home Dir>:<Default Shell>
tester1:tester1!:6001:6011:testaccount:/home/tester1:/bin/bash
tester2:tester2!:6002:6012:testaccount:/home/tester2:/bin/bash
tester3:tester3!:6003:6013:testaccount:/home/tester3:/bin/bash



 

Dear,

I am currently in my graduation year of my IT networking school, and now one teacher has decided to give us some lessons in linux, no harm right?

I am going trough the course with ease but now he has asked us to make a script to add users manually into the passwd and shadow file from a csv / txt file with a script, unfortunately we were not allowed to use the adduser or useradd command which has left me completely clueless on how to do it.

 

Does anyone have any tips or an example script?

 

Thanks for your help!

Link to post
Share on other sites

4 minutes ago, unijab said:

Do you even know bash yet?

Have a look into sed and awk that might help some

The assignment states it has to be done in bash, don't ask me why, it just has to.. , Thanks for the suggestion anyway

Link to post
Share on other sites

4 minutes ago, aurrorax said:

Could you give me an example? I don't understand how it is done.

The first link I gave was probably less than useful; didn't realize it using newusers. My bad, on that. These should hopefully be more of use. That said, if you're allowed to use the newusers command, it does most of the work for you... you could create a bash script that takes an argument (file of users + passwords) and just passes it to the newusers command. 

https://askubuntu.com/a/292573

https://www.howtoforge.com/user_password_creating_with_a_bash_script

Link to post
Share on other sites

1 minute ago, Jade said:

The first link I gave was probably less than useful; didn't realize it using newusers. My bad, on that. These should hopefully be more of use. That said, if you're allowed to use the newusers command, it does most of the work for you... you could create a bash script that takes an argument (file of users + passwords) and just passes it to the newusers command. 

https://askubuntu.com/a/292573

https://www.howtoforge.com/user_password_creating_with_a_bash_script

I have found this aswel, unfortunately I am not allowed to use adduser or useradd , newusers is allowed.

Link to post
Share on other sites

18 minutes ago, aurrorax said:

I have found this aswel, unfortunately I am not allowed to use adduser or useradd , newusers is allowed.

Should be easy enough, then. Here's the manpage for newusers -- not gonna do all your work. ;)

This code is untested and I can't be held liable for it, all that legal stuffs.

How to run the script:

./myUserScript thisListOfImportedUsers

What's in the script, theoretically. $1 is variable 1 (argument -- thisListOfImportedUsers)

#!/bin/bash

newusers $1

What's in thisListOfImportedUsers - formatted as 

<Username>:<Password>:<UID>:<GID>:<User Info>:<Home Dir>:<Default Shell>
tester1:tester1!:6001:6011:testaccount:/home/tester1:/bin/bash
tester2:tester2!:6002:6012:testaccount:/home/tester2:/bin/bash
tester3:tester3!:6003:6013:testaccount:/home/tester3:/bin/bash



 
Link to post
Share on other sites

On 31-1-2016 at 0:55 AM, Jade said:

Should be easy enough, then. Here's the manpage for newusers -- not gonna do all your work. ;)

This code is untested and I can't be held liable for it, all that legal stuffs.

How to run the script:


./myUserScript thisListOfImportedUsers

What's in the script, theoretically. $1 is variable 1 (argument -- thisListOfImportedUsers)


#!/bin/bash

newusers $1

What's in thisListOfImportedUsers - formatted as 


<Username>:<Password>:<UID>:<GID>:<User Info>:<Home Dir>:<Default Shell>

tester1:tester1!:6001:6011:testaccount:/home/tester1:/bin/bash
tester2:tester2!:6002:6012:testaccount:/home/tester2:/bin/bash
tester3:tester3!:6003:6013:testaccount:/home/tester3:/bin/bash


 

Thank you for this, this has helped me alot unfortunately there seems to be a bug present in ubuntu at the moment that prevens adding more than 2 users at once, trying mint as we speak.

 

source : https://bugs.launchpad.net/ubuntu/+source/shadow/+bug/1266675

             http://comments.gmane.org/gmane.linux.debian.alioth.pkg-shadow/3327

 

Link to post
Share on other sites

55 minutes ago, aurrorax said:

Thank you for this, this has helped me alot unfortunately there seems to be a bug present in ubuntu at the moment that prevens adding more than 2 users at once, trying mint as we speak.

 

source : https://bugs.launchpad.net/ubuntu/+source/shadow/+bug/1266675

             http://comments.gmane.org/gmane.linux.debian.alioth.pkg-shadow/3327

 

I would've caught that if I had tested the stuff I gave you -- my bad on that. Your best bet is a different distro (Cent, perhaps?)  entirely, 'cause Mint is based on Ubuntu. 

Link to post
Share on other sites

6 hours ago, SSL said:

It's 2016, let's use configuration management systems for this kind of thing, instead of writing brittle shell scripts.

  • Puppet
  • Salt
  • Chef
  • Ansible

And so on. Oh, but it's for a class. Bummer!

know where I can find in depth tutorials on puppet?

Can Anybody Link A Virtual Machine while I go download some RAM?

 

Link to post
Share on other sites

23 minutes ago, unijab said:

know where I can find in depth tutorials on puppet?

http://garylarizza.com/

https://docs.puppetlabs.com/pe/latest/quick_start.html

http://docs.puppetlabs.com/puppet/latest/reference/

 

Puppet docs are actually a pretty good place to start. Just remember that Puppet is a declarative, domain specific language; it's not procedural and doesn't have control flow. It enforces state, not behavior.

Link to post
Share on other sites

  • 2 weeks later...
On 2/3/2016 at 5:29 PM, Jade said:

I would've caught that if I had tested the stuff I gave you -- my bad on that. Your best bet is a different distro (Cent, perhaps?)  entirely, 'cause Mint is based on Ubuntu. 

Sorry for the delayed response!

Mint did actually work, thanks for your help.

I am still awaiting approval from my teacher I'll let you know :)

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×