Linux user permission right way

To solve linux user and group permission issue for any kind of project.

First of all find the right user and right group which is executing that process.

Silver bullet of linux user permission.

sudo lsof -iTCP -sTCP:LISTEN -Pn
export OWENRE=$(whoami)
export GROUP=$(whoami)

Use above command to grap process and find whois the right owner of that process and export variable as OWENRE and GROUP

sudo chgrp $GROUP * -Rf
sudo chown $OWENRE * -Rf
sudo find ./ -type f -exec chmod 664 {} \;    
sudo find ./ -type d -exec chmod 775 {} \;

Rre-read image for more understanding.

Don't use 0777 or 777 for...

sudo command with no password in linux!

How to avoide repetation of sudo command in linux.

Just follow bellow steps to avoide repation.

Create file or edit if exist

sudo visudo -f /etc/sudoers.d/90-cloudimg-ubuntu

Change username as per your suite

# ubuntu user is default user in cloud-images.
# It needs passwordless sudo functionality.
ubuntu ALL=(ALL) NOPASSWD:ALL

npm permission issue

This is general solutions for all kind of npm permission issue.

sudo chown -R $USER ~/.npm
sudo chown -R  $USER /usr/bin/npm
sudo chown -R  $USER /usr/lib/node_modules/
chmod -R a+x node_modules