Script to create a linux user on one server, when a DB user is made on another?

Hello all,
    I am looking for a way to have a linux user created on a sFTP gateway automatically with the credentials that were used when a user was created in a database. We have a web application in which we onboard a user and create their account. We would then have to go and manually create a linux user on the sFTP gateway, as it uses standard linux users as the credentials to login to FTP.

Is there a script (perhaps bash or python?) that can either use some sort of trigger to know when a DB user is made, then create a user on the FTP server. If it can use the same credentials that would be ideal, but if not, it can create a random password and then we can have it email it to the user perhaps. If there is nothing made already, if someone could point me in the right direction as to the best way to go about this, or what language would be ideal, please do.

MostHatedIT ManagerAsked:
Who is Participating?
Erik SchminkeAIX/Linux Systems AdministratorCommented:
Depending on which database you're using, you might be able to drive execution of the adduser command from a database event.

I've not tested this, so your mileage may vary... but this page appears to demonstrate how to make a "CREATE TRIGGER" that will execute a system command from a MySQL database.

Once you have a new record firing a system command, you can easily create a script that makes the appropriate adduser command.

If the adduser script needs to be execute command on a remote system, you could use SSH keys for that.

Solving those general problems in that order should get you to where you want to be.
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
This will be a custom script based on your environment.

You'll just fire off ssh + command to create new user on your SFTP gateway machine.

You'd fire off your ssh command each time you onboard a new database user.

You might go one step further + run a nightly CRON job to check all database users against SFTP gateway users + notify someone if there's a mismatch, which means your ssh command failed.
MostHatedIT ManagerAuthor Commented:
Thanks for the info. I actually ended up doing something very close to that just before you replied. All s well. : )
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.