This is just a bad idea that I just had.
Is there a way create users accounts on the fly?
Say I have a Ubuntu vm created, and I want to give a bunch of people access. But for whatever reason I don't particularly care about what they do with it.
How can I set it up that when user A ssh into the vm the user's account will automatically be created?
and yes, I know in theory, I could just create a guest account and share that with the people that need access. but then a bunch of people will be sharing the account and I also want to log what everybody did so having them on the same account would make it very difficult.
and yes, this is a very bad idea.
I like a challenge. Yes you can do this, if you are willing to let the first ssh fail. The following script (which I actually tested) tails the sshd log, which by default (on my system) produces lines like this on a failed ssh login:
When such a line is matched, the user id (dummy in this example) is extracted and a user account is created with a encrypted password which is the same as the user id (dummy). A second attempt to login will now work.
The user might like to then copy their key to the remote:
If they dont have a key yet, first do:
Using
python
:When a user try to login into a computer via
ssh
who does not have an existing account will be denied to login and this incident will be recorded in the/var/log/auth.log
file having a line e.g.:we will exploit this line to extract the username provided to create an account for that user so that from next time the user can login without any problem
We have used the password as the username given plus
123
(the salt isfoobar12
) i.e. if a username isspamegg
the password will bespamegg123
. You can change it and the salt to any value you want and of course the user must change the password after login for the first timeIn this approach all the usernames from the
/var/log/auth.log
file are taken into a list and similarly all usernames from/etc/passwd
are also taken in a list.Then we have checked if the entered username exists already, if not then the user is created with the password mentioned earlier.
You can run it as a
cron
job to make sure the usernames get added automatically.