3

I have seen npm adduser, but i can figure it out how to manage this inside mine code. What i have to do is to create new user from nodejs server code inside linux server, and change chmod and chown of that user and folders it content.

1 Answer 1

1

Use child_process.execFile to execute /usr/sbin/adduser, /bin/chmod and /bin/chown

Otherwise you can use exec from npm if your version of nodejs doesn't have child_process.execFile

Sign up to request clarification or add additional context in comments.

2 Comments

Doing this from a node process assumes the process is running as 'root', which is a bad idea. The proper way would be to add the user under which the process will run to the /etc/sudoers file with the proper magic to only run useradd as root without a password. See ducea.com/2006/05/19/…
I agree with @RobRaisch and do what he said, but with exec i cant use sudo, or just cant find how. Without sudo working perfectly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.