Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pm2 - Startup script for non-root user permission denied

Tags:

node.js

root

pm2

I just installed pm2 (on Debian 9) and I need to run NodeJS server of few users. Every user have own NodeJS server what I need to run under them. Not under root.

For example I have user "user1":

  • I can control pm2 normally
  • This command on user1 for enabling startup scripts: pm2 startup
  • Then I copypaste outputed command to root and execute...
  • Startup script for given user is now created

pm2 still works on user1, but after restart I cannot control pm2 and Iam getting this error: [PM2][ERROR] Permission denied, to give access to current user: $ sudo chown user1:user1 /home/user1/.pm2/rpc.sock /home/user1/.pm2/pub.sock

If I execute this command on root, I can then again control pm2 on user1, but all NodeJS servers are executed as root!!

I need to 'grant' permissions every restart..

How to fix this?

like image 508
Baterka Avatar asked Dec 13 '22 17:12

Baterka


1 Answers

I'm not sure if there are any risk with the following method, but it did solve same issue I was facing.

1- open new terminal (fresh, without sudo permission)
2- sudo chmod -R 777 /home/user1/.pm2 (gives permission to the .pm2 folder)
3- pm2 start index.js (Note that there is no sudo here)
4- pm2 save
5- pm2 startup
6- Restart your computer and check pm2 monit
7- It should list your index process now. If not, try from 1-5, 8, and then 6.
8- paste the command listed in step 5
like image 102
Satys Avatar answered Dec 21 '22 09:12

Satys