1

I've been googling around and didn't find valuable answer.

I have 98 students. I want to create, for each student a directory where they can upload their own files.

Unless I'm wrong, it seems I'll have to:

  • create a student account
  • change its password to a strong one
  • do this again 98 times!

I would like:

1 - to avoid if possible creating accounts i.e. just configuring vsftp properly and avoid useradd (= avoid the step # 6 of this tutorial)

2 - find a way to change all those students passwords to strong ones, (and of course be able to print them to mail them individually).

1 Answer 1

0

This is a template to get the ball rolling. It's a perl script that prints out commands so it will not do anything until you decide to hilight the commands and cut/paste it back into the console.

It does the hard work of generating to user accounts, sets passwords and optionally create or not create a homedirectory. The trick is when creating passwords for the adduser command it needs to be in crypt3 format. So if you run this script...

#!/usr/bin/perl
use strict;         

my $SALT="jhgk^djfh*gkdh(jghkdhj786876erg98rhj44";
my $user="student";
my $pass="password";
my $encrypted;
my $studno=1;
my $studentstogenerate=20;

for ($studno;$studno<$studentstogenerate;$studno++) {
 $pass='p'.int(rand(100000000000000));
 $encrypted=crypt($pass, $SALT); 
 print "sudo useradd -p '$encrypted'  $user$studno --no-create-home -G ftpgroup # actual pass ($pass)\n";
}

It will generate...

sudo useradd -p 'jhVU3sDajDruY'  student1 --no-create-home -G ftpgroup # actual pass (p67228866189634)
sudo useradd -p 'jhViMGmmQ7d4.'  student2 --no-create-home -G ftpgroup # actual pass (p20494616343373)
sudo useradd -p 'jhMr3VKBG2.ow'  student3 --no-create-home -G ftpgroup # actual pass (p13933001113231)
sudo useradd -p 'jhqPnvxZCcQTg'  student4 --no-create-home -G ftpgroup # actual pass (p45579091049416)
sudo useradd -p 'jhWqVroWUraWk'  student5 --no-create-home -G ftpgroup # actual pass (p35233656259977)
sudo useradd -p 'jhlWOWyt0AKYE'  student6 --no-create-home -G ftpgroup # actual pass (p39944882363487)
sudo useradd -p 'jhJd1AVEU/FE6'  student7 --no-create-home -G ftpgroup # actual pass (p71192849790380)
sudo useradd -p 'jh1I6aDAkq3iA'  student8 --no-create-home -G ftpgroup # actual pass (p41868457411791)

As it uses a random number generator everytime you run it the password will be different.

So in this case student1 has a password of p67228866189634

You can play with this script to generate different output by chnaging the variables. Should be easy enough even if you don't program in perl.

Note: I have added the students to ftpgoup which you might need to change based on the group you used.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .