SSH Run Node.js app as another user on system restart

I've installed ghost blog to my digitalocean droplet.

Everything's running fine with root user.

However, I've created another user to run apps (including ghost) to make things more secure.

I've installed pm2, following this guide https://www.digitalocean.com/community/tutorials/how-to-use-pm2-to-setup-a-node-js-production-environment-on-an-ubuntu-vps. I also have forever installed.

The problem is, I'm not able to start my blog with the created user since the blog is located at /var/www -- When I sudo-start, it of course works, however I'm not sure if it's possible to add apps to startup to run as another user?

If there is a way, I would love to know.

Try this:

Move your blog location to /var/www/[blog_directory]

Where blog_directory is "ghost" or the name of your blog, or whatever.

e.g., /var/www/ghost

Then make sure your permissions look like this:

Permissions on /var:

  drwxr-xr-x 21 root root  4096 Oct 20 23:55 var

Permission on /var/www:

 drwxr-xr-x  8 root root  4096 Oct  1 01:04 www

Notice that everybody has directory execute permissions on both /var and /var/www

Then chown and chmod the actual blog directory so that your blog user has rwx permissions

  chown -R [blog_user] [blog_dir]
  chmod 755 [blog_dir]      

You should now be able to start the blog as blog_user

Or, you could just visudo to add the necessary permissions for your blog_user to run the blog and use "sudo [blah]" in the various script files.