Connor McNally
Connor McNally

Reputation: 13

Executing SSH commands from Google Apps script

I'm trying to create a Google apps script that adds a new user to a Ubuntu vm that I've created whenever a form is submitted. I'm wondering if there is some way to initiate an ssh connection from a Google apps script that would allow me to login to the vm and create a new user. I have the IP and login credentials for the vm. I've set it up so that the script will run whenever a form is submitted, however I'm not sure where to go from there. I apologize in advance if there is a better way to do this, I could just manually create the accounts based off form submissions, but I really need the automation. If there is a solution to this, even if it doesn't involve ssh, I would really appreciate the help!

Upvotes: 1

Views: 2455

Answers (1)

ZektorH
ZektorH

Reputation: 2770

This is not trivial.

Google AppsScript does not support SSH by default, so you have to work around that.

The user Perhaps you see this name has given you a great idea. I'll further explain how to do what he suggested below:

What you will need on the linux machine

  • A web service, callable from the google IPs (you can white list it or leave it open to the public (which is dangerous, and should be done only as last resort)).
  • A account with user creation permission on linux.
  • A script to create the new users from the data received on the web service.

For the first part, you can do this with any technology you want. I recommend Node.Js + Express.js, as it is easy to create what you want with child processes.

I'll assume you already have an user account able to create users. You probably want to use that.

The last part is just another linux command. You can just Google it and you'll find lots of examples.

There is one catch, while the real-time user creation option with APIs might look enticing to you, I would strongly advise against leaving a public service for something like creating users, as that could become a security risk.

What you might want to do instead is to have a machine with no value (AKA a cheap machine your planned to throw away, with no important data and no confidential information) hosting your web service and then make a script on your Ubuntu VM to fetch the data from said service in an encrypted secure way.

Upvotes: 1

Related Questions